Creating a scatter plot with patch

10 ビュー (過去 30 日間)
David K
David K 2024 年 2 月 15 日
コメント済み: Voss 2024 年 2 月 15 日
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 Center および File ExchangeGraphics Performance についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by