Normalize y axis in Matlab histogram

조회 수: 7 (최근 30일)
Mons Nasery
Mons Nasery 2015년 10월 1일
댓글: Steven Lord 2015년 10월 1일
Hi,
suppose I have this histogram:
histogram([resultCastMatch.jaccard]);
Is this the correct way to normalize y axis (so to show y axix as percentage)?
histogram([resultCastMatch.jaccard]);
ylabels = get(gca, 'YTickLabel');
ylabels = linspace(0,100,length(ylabels));
set(gca,'YTickLabel',ylabels);

답변 (2개)

Geoff Hayes
Geoff Hayes 2015년 10월 1일
Mons - no, I don't think that is the way to go about converting the y-axis to percentages. Remember, the ticks along the y-axis will just tell you the number of elements that fall into each of your bins. So if you want to convert these ticks (or heights) to percentages, you would have to divide each tick by the total number of elements across all bins. Or, depending upon your version of MATLAB, you may be able to specify the Normalization property to have a value of probability (which would produce the desired result without you having to manipulate the ticks). See http://www.mathworks.com/help/matlab/ref/histogram.html#namevaluepairarguments and look for the section on Normalization.
  댓글 수: 2
Mons Nasery
Mons Nasery 2015년 10월 1일
thanks for your useful link :)
Steven Lord
Steven Lord 2015년 10월 1일
I second Geoff's suggestion of specifying the 'probability' value for the 'Normalization' argument.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2015년 10월 1일
Not quite. You have to specify the YTick values as well as the YTickLabel labels:
figure(1)
h1 = histogram(randi(9, 1, 25))
yt = get(gca, 'YTick'); % Get Y-Tick Values
set(gca, 'YTick',yt, 'YTickLabel',yt*4) % Since Data Vector Is (1x25), Multiply ‘yt’ By 4 To Get Percent
ylabel('Percent')
  댓글 수: 2
Mons Nasery
Mons Nasery 2015년 10월 1일
thanks for your kind answer. So, in my case which the y axis shows the number of users and I have 164 users, is it correct?
figure;
h1 = histogram([resultGenreMatch.jaccard]);
yt = get(gca, 'YTick');
set(gca, 'YTick',yt, 'YTickLabel',yt*(100/164));
Star Strider
Star Strider 2015년 10월 1일
My pleasure.
That looks correct to me. It should work.

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by