Creating a scatter plot with patch

14 views (last 30 days)
David K
David K on 15 Feb 2024
Commented: Voss on 15 Feb 2024
I am working with code created by someone else long ago that performs a lot of complex custom plotting tasks. I also have my own tools which I have developed to perform similar functions, but I've found the old tools tend to work more quickly and efficiently so am trying to implement some of their techniques into my own tools. One thing I've discovered is that when the older tools are plotting a bunch of markers with color that varies by a variable, the code uses the patch function with the FaceColor value set to 'none'. In my own tools I would use scatter to perform the same function. Is there any benefit to using patch to create a colored scatter plot over scatter? I did learn that using line rather than plot can reduce some of the overhead when updating the axis, so I wondered if there might be something similar between patch and scatter.

Accepted Answer

Voss
Voss on 15 Feb 2024
"I wondered if there might be something similar between patch and scatter"
I would expect so. See this:
Generally, if your code is controlling the axes, then use low-level functions (line, patch, surface, etc.) and set those objects' properties (XData, YData, FaceColor, etc.) when they need to be updated. Otherwise, if you want to rely on MATLAB automatically updating the axes, then use high-level functions (plot, fill, surf, scatter, etc.).
Specifically regarding the question of a scatter plot vs a patch with FaceColor='none' (presumably with LineStyle='none' as well?), I don't see why you couldn't just use line for that, but maybe I'm missing something.
  2 Comments
David K
David K on 15 Feb 2024
Thanks, that's helpful. I can't use line in this particular case because I want the marker color to vary by value. As far as I know, line only allows one color for all markers in the object.
Voss
Voss on 15 Feb 2024
You're welcome!
"I can't use line in this particular case because I want the marker color to vary by value."
Oh yeah, you did say that in the question, and I just wasn't thinking about it when I wrote my answer. My mistake.
"As far as I know, line only allows one color for all markers in the object."
Correct.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!