MATLAB Answers

How can I plot an histogram?

2 ビュー (過去 30 日間)
Chiara Scarpellini
Chiara Scarpellini 2021 年 9 月 12 日
編集済み: Star Strider 2021 年 9 月 12 日
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')

採用された回答

Star Strider
Star Strider 2021 年 9 月 12 日
編集済み: Star Strider 2021 年 9 月 12 日
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.
.

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 9 月 12 日
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')

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by