Change histogram y-axis to percentage [R2017b]
363 ビュー (過去 30 日間)
I have used the histogram function to get a plot of a histogram. Specifically, for presentation, I would actually only like to have the probability value as a percentage plotted against the bins. For this I have used the histogram properties 'Normalisation' set to 'probability' and 'DisplayStyle' set to stairs'. I need the y-axis as a percentage. I see that I cannot access the histogram.Data values as they are read only and therefore I cannot modify them. I was simply going to multiply them by 100.
Is there anyway to plot this data from the histogram function as: 1) a line plot; 2) with y-axis values as percentage so that when I zoom in and out the percentage also re-scales rather than just setting yticklabels.
回答 (3 件)
Star Strider 2018 年 1 月 17 日
I’m not certain what you’ve already done.
The 'YTick' values are available, and you can modify them as you would with any other usual axis object.
d = randn(1, 1000); % Create Data
histogram(d, 50, 'Normalization','probability', 'DisplayStyle','stairs')
histogram(d, 50, 'Normalization','probability', 'DisplayStyle','stairs');
ytix = get(gca, 'YTick')
set(gca, 'YTick',ytix, 'YTickLabel',ytix*100)
Compare the two figures to see the result of recalculating the 'YTick' values in the second histogram.
Andreas Vester 2018 年 3 月 8 日
Browse the MATLAB documentation for 'yticks' and 'yticklabels'.
One solution might be as follows:
Tony Castillo 2020 年 4 月 17 日
I have plotted a histogram I wonder if is possible to set another axis in the plot like the one in the figure attached, would you mind telling me how to do it, please?.