필터 지우기
필터 지우기

Plot range of values in a bar graph

조회 수: 31 (최근 30일)
Brendan Görres
Brendan Görres 2020년 10월 16일
편집: Ameer Hamza 2020년 10월 16일
I am looking to create a bar graph that outputs a certain range of values, for example the minimum to maximum temperature of a Body. The label on the x axis to the appropriate bar should be a char representing the name of the Body (So in this simple example the output would be just one bar graph). How can I do this?

답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 10월 16일
편집: Ameer Hamza 2020년 10월 16일
This is one of the possible ways
x = categorical({'First label', 'Second label', 'Third label'});
ymin = [1 2 5]; % heights of bar
ymax = [4 9 8];
b = bar(x, [ymin; ymax-ymin].', 'stacked');
b(1).Visible = 'off';
  댓글 수: 2
Brendan Görres
Brendan Görres 2020년 10월 16일
hey Ameer
unfortuneatly this is not what I am looking for. This code gives out a bar chart with two bar graphs where First Label is of height 1 and Second Label of height 2.
To go with your example: I would like to output a graph with the label 'First label' that starts at height 1 and ends at height 2 (so 1 is the minimum value and 2 the maximum value). Note that this graph is not starting at zero but rather at 1 (or in general it starts at the minumum value and ends at the maximum value).
Ameer Hamza
Ameer Hamza 2020년 10월 16일
Updated answer shows how you can achieve the result as you mentioned in comment.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2020년 10월 16일
I was not certain what result you wanted when I replied to your Comment to Plot range of values as bars. I gave a sort of general reply.
Try this slight variation on that code:
Tmax = randi([25 30], 1, 10); % Create Data
Tmin = randi([15 20], 1, 10); % Create Data
days = 1:10; % Create Data
figure
plot([days; days], [Tmin; Tmax], 'LineWidth',5)
xlabel('Day')
ylabel('Temperature Range (°C)')
ylim([10 40])
xlim([0 11])
grid
xtl = compose('Day #%2d',days);
Ax = gca;
Ax.XTickLabel = [];
set(gca,'XTick',days, 'XTickLabel',xtl, 'XTickLabelRotation',15)
.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by