How can I plot an histogram?

조회 수: 1 (최근 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')

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by