Plot range of values in a bar graph
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (2)
Ameer Hamza
le 16 Oct 2020
Modifié(e) : Ameer Hamza
le 16 Oct 2020
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 commentaires
Ameer Hamza
le 16 Oct 2020
Updated answer shows how you can achieve the result as you mentioned in comment.
Star Strider
le 16 Oct 2020
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)
.
0 commentaires
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!