Snakecharts in Matlab App Designer

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

采纳的回答

Harald
Harald 2025-2-7
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 个评论
Harald
Harald 2025-2-10
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by