Creating a scatter plot with patch

8 次查看(过去 30 天)
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.

采纳的回答

Voss
Voss 2024-2-15
"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 个评论
David K
David K 2024-2-15
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 2024-2-15
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by