Snakecharts in Matlab App Designer

1 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

Harald
Harald il 7 Feb 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 Commenti
Harald
Harald il 10 Feb 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 il 11 Feb 2025
Thank you Harald!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by