Snakecharts in Matlab App Designer

조회 수: 1 (최근 30일)
Andrea Quintarelli
Andrea Quintarelli 2025년 2월 7일
댓글: Andrea Quintarelli 2025년 2월 11일
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
Andrea Quintarelli
Andrea Quintarelli 2025년 2월 11일
Thank you 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