필터 지우기
필터 지우기

Histogram occurences per class

조회 수: 11 (최근 30일)
Nina Perf
Nina Perf 2022년 4월 26일
편집: Nina Perf 2022년 4월 26일
Hi,
I want to have the classes count centered at the top of each bar, as a number. Can you please help?
figure()
h = histogram(Sum.tClasses)
ylabel('Occurrences', 'fontsize', 14)
xticks([1 2 3 4])

채택된 답변

Steven Lord
Steven Lord 2022년 4월 26일
Let's make some sample data and plot the histogram using the 'integers' BinMethod. In this case each integer in my data set gets its own bin.
x = randi(5, 1, 100);
h = histogram(x, 'BinMethod', 'integers');
To make working with the properties easier, extract two of them into variables with short names.
c = h.BinCounts;
E = h.BinEdges;
Find the X coordinate of the center of each bar.
centers = (E(1:end-1)+E(2:end))/2;
Write the bin counts data 1 unit above the top of each bar. If your counts were larger than this you might want to increase that offset or use a multiplicative factor (put it 10% above the bar by using 1.1*c instead of c+1, as an example.)
text(centers, c+1, string(c))

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by