Snakecharts in Matlab App Designer

1 visualización (últimos 30 días)
Andrea Quintarelli
Andrea Quintarelli el 7 de Feb. de 2025
Comentada: Andrea Quintarelli el 11 de Feb. de 2025
Hi everyone,
I am trying to understand how to generate the kind of plot you can see in the picture attached.
What you basically have there is something like an horizontal histogram, where the important bit are the green bars (that do not start from "0" on their own scale or, in other words, need to be between a start and end value). Each of those bars would need to have different scale (different max and min values for the whole line and, inside those, the green bar).
On top of that, I would need to draw a line that goes through each bar and meet a point, on each bar. Each point need to be positioned horizontally respecting the same scale (min and max value) of each bar.
Do you have any idea on how I could get there?
Thank you very much!

Respuesta aceptada

Harald
Harald el 7 de Feb. de 2025
Hi,
you can use a stacked barh and modify the colors. Modifying an example in the barh doc:
x = [1980 1990 2000];
y = [15 20 5; 10 17 21; 10 5 15];
b = barh(x,y,'stacked');
b(1).FaceColor = [0.5 0.5 0.5];
b(2).FaceColor = [0 0.5 0];
b(3).FaceColor = [0.5 0.5 0.5];
Adding the line on top after a hold on should not be too difficult, and text can be used for inserting the text.
Best wishes,
Harald
  3 comentarios
Harald
Harald el 10 de Feb. de 2025
Hi Andrea,
Yes, you can add a line on top of barh.
x = [1980 1990 2000];
y = [15 20 5; 10 17 21; 10 5 15];
b = barh(x,y,'stacked');
b(1).FaceColor = [0.5 0.5 0.5];
b(2).FaceColor = [0 0.5 0];
b(3).FaceColor = [0.5 0.5 0.5];
hold on
plot([25 20 12], x, "r.-", "LineWidth", 2, "MarkerSize", 30)
hold off
I would implement "different scaling for each bar" by using multiple x-axes. Approaches for that are available on File Exchange, e.g. https://www.mathworks.com/matlabcentral/fileexchange/65044-plotmultix-varargin .
Best wishes,
Harald
Andrea Quintarelli
Andrea Quintarelli el 11 de Feb. de 2025
Thank you Harald!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Discrete Data Plots en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by