Creating a scatter plot with patch

14 visualizaciones (últimos 30 días)
David K
David K el 15 de Feb. de 2024
Comentada: Voss el 15 de Feb. de 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.

Respuesta aceptada

Voss
Voss el 15 de Feb. de 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 comentarios
David K
David K el 15 de Feb. de 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 el 15 de Feb. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by