How can I plot an histogram?

1 vue (au cours des 30 derniers jours)
Chiara Scarpellini
Chiara Scarpellini le 12 Sep 2021
Modifié(e) : Star Strider le 12 Sep 2021
I need to plot an histogram with these values:
number_of_events=[30.60, 32.30, 32.30, 32.30, 32.30, 2.60, 12.60, 32.30, 32.30, 9.70, 25, 13.20, 18.10, 32.30, 2.50, 32.30]
I don't know why this is not working
number_of_events=number_of_events
figure
histogram(number_of_events,16)
ylim([0 35])
ylabel('Number of events per year')
xticks('27CRA01','23ARV00','29CRD99','28XRA01','15ART03','08BRS01','26ARB01','34XRJ01','34XRI01','00LYF01','31ARA01','05BRM01','29BRL99','34XRH01','20ARB01','00OR100')
title('Times CSOs discharge per year')

Réponse acceptée

Star Strider
Star Strider le 12 Sep 2021
Modifié(e) : Star Strider le 12 Sep 2021
Try something like this —
number_of_events=[30.60, 32.30, 32.30, 32.30, 32.30, 2.60, 12.60, 32.30, 32.30, 9.70, 25, 13.20, 18.10, 32.30, 2.50, 32.30];
number_of_events=number_of_events;
figure
hh = histogram(number_of_events,16);
BinCtrs = hh.BinEdges(1:end-1) + mean(diff(hh.BinEdges))/2;
ylim([0 35])
ylabel('Number of events per year')
xtickc = {'27CRA01','23ARV00','29CRD99','28XRA01','15ART03','08BRS01','26ARB01','34XRJ01','34XRI01','00LYF01','31ARA01','05BRM01','29BRL99','34XRH01','20ARB01','00OR100'};
set(gca, 'XTick',BinCtrs, 'XTickLabel',xtickc)
title('Times CSOs discharge per year')
Experiment to get different results.
However, if you want to plot a bar plot and not compute the histogram —
number_of_events=[30.60, 32.30, 32.30, 32.30, 32.30, 2.60, 12.60, 32.30, 32.30, 9.70, 25, 13.20, 18.10, 32.30, 2.50, 32.30];
number_of_events=number_of_events;
figure
hb = bar(number_of_events);
% BinCtrs = hh.BinEdges(1:end-1) + mean(diff(hh.BinEdges))/2;
ylim([0 35])
ylabel('Number of events per year')
xtickc = {'27CRA01','23ARV00','29CRD99','28XRA01','15ART03','08BRS01','26ARB01','34XRJ01','34XRI01','00LYF01','31ARA01','05BRM01','29BRL99','34XRH01','20ARB01','00OR100'};
set(gca, 'XTick',hb.XData, 'XTickLabel',xtickc)
title('Times CSOs discharge per year')
Experiment to get different results.
.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 12 Sep 2021
there is an err in your code. Here is the corrected one:
number_of_events=[30.60, 32.30, 32.30, 32.30, 32.30, 2.60, 12.60, 32.30,32.30, 9.70, 25, 13.20, 18.10, 32.30, 2.50, 32.30];
histogram(number_of_events,16)
ylim([0 35])
ylabel('Number of events per year')
xticklabels({'27CRA01','23ARV00','29CRD99','28XRA01','15ART03','08BRS01','26ARB01','34XRJ01','34XRI01','00LYF01','31ARA01','05BRM01','29BRL99','34XRH01','20ARB01','00OR100'})
xtickangle(45)
title('Times CSOs discharge per year')

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by