Normalize y axis in Matlab histogram

6 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by