Hello Community,
i want to ask a question about bar graph. By default the beginning of each bar is zero-value. I need to show such group of bars (that means no 'stacked' style), while bar beginning shows minimum value and bar ending shows maximum value. Minimum and maximum is not always negative and positive respectively. That means the bar in bar group could just "hang is the air".
How can i do this? I could do this through 'stacked' style, making first bar invicible. But i need exact grouped style.
Please help and thank you!
Maksym Klitsman

2 Kommentare

José-Luis
José-Luis am 11 Aug. 2017
Could you post an example of the look you are trying to achieve?
Maksym Klitsman
Maksym Klitsman am 11 Aug. 2017
of course, sorry if I not clearly told what i want

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

José-Luis
José-Luis am 11 Aug. 2017

2 Stimmen

aH = axes;
minimum = rand(10,3);
maximum = rand(10,3) + minimum;
bH = bar(maximum);
hold on;
bH1 = bar(minimum);
for ii = bH1
ii.FaceColor = [1 1 1];
ii.LineStyle = 'None';
ii.EdgeColor = [1 1 1];
end
for ii = bH
ii.LineStyle = 'None';
ii.EdgeColor = [1 1 1];
end
axes('Position',aH.Position,'XTick',[],'YTick',[],'Color','None');

2 Kommentare

Maksym Klitsman
Maksym Klitsman am 11 Aug. 2017
thanks, that's exactly what i wanted to represent!
José-Luis
José-Luis am 11 Aug. 2017
My pleasure.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Akira Agata
Akira Agata am 11 Aug. 2017

4 Stimmen

If my understanding is correct, what you want to do would be like the following. Is it answering your question??
% Example of min. and max. value of each bar
minimum = [1;-1;3];
maximum = [5;3;7];
h = bar([minimum, maximum-minimum],'stacked','BaseValue',min(minimum));
h(1).Visible = 'off';
set(gca,'YLim',[min(minimum),max(maximum)+1]);

5 Kommentare

Maksym Klitsman
Maksym Klitsman am 11 Aug. 2017
Thanks for the answer. Your understood me correctly, but i have noticed, i need represent a group of bars. In example min and max values of data1 and data2. That's why i need a 'grouped' style
That what i want should look this way:
Akira Agata
Akira Agata am 11 Aug. 2017
Bearbeitet: Akira Agata am 11 Aug. 2017
OK. In that case, maybe bar function is not sufficient and you should make your own bar chart by arranging many rectangle shapes, like:
% Example of min. and max. value of each bar for each group (A&B)
A_minimum = [1;-1;3];
A_maximum = [5;3;7];
B_minimum = [-3;1;1];
B_maximum = [2;5;6];
% Calculate hight of each bar
A_height = A_maximum - A_minimum;
B_height = B_maximum - B_minimum;
% Make bar chart using rectangle
figure
hold on;
for kk = 1:3
rectangle(...
'Position', [(kk-1)*3,A_minimum(kk),1,A_height(kk)],...
'FaceColor', 'c');
rectangle(...
'Position', [(kk-1)*3+1,B_minimum(kk),1,B_height(kk)],...
'FaceColor', 'g');
end
ax = gca;
ax.XTick = [1,4,7];
ax.XTickLabel = {'group1','group2','group3'};
Aurea94
Aurea94 am 9 Nov. 2021
This is just what I am looking for! Thank you very much!
Which would be the way to have this in a 3D plot? I have different set of values which would need to be plot in a third axis.
Thank you very much!
Thomas Wiesen
Thomas Wiesen am 28 Jan. 2022
I have a similar issue. I want a bar chart where the bottom of the bar is at some minimum value and the top of the bar is at some maximum value. Does Akira Agata’s code work when there are negative elements? In the second bar, the bottom of the bar should be at -1 and the top of the bar should be at 3. However, when I used this code, the top of the second bar is at 4.
Paris Pasqualin
Paris Pasqualin am 26 Apr. 2022
Amazing, thank you.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Labels and Annotations finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by