Normalize y axis in Matlab histogram

7 visualizaciones (últimos 30 días)
Mons Nasery
Mons Nasery el 1 de Oct. de 2015
Comentada: Steven Lord el 1 de Oct. de 2015
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);

Respuestas (2)

Geoff Hayes
Geoff Hayes el 1 de Oct. de 2015
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 comentarios
Mons Nasery
Mons Nasery el 1 de Oct. de 2015
thanks for your useful link :)
Steven Lord
Steven Lord el 1 de Oct. de 2015
I second Geoff's suggestion of specifying the 'probability' value for the 'Normalization' argument.

Iniciar sesión para comentar.


Star Strider
Star Strider el 1 de Oct. de 2015
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 comentarios
Mons Nasery
Mons Nasery el 1 de Oct. de 2015
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 el 1 de Oct. de 2015
My pleasure.
That looks correct to me. It should work.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by