# How to rescale the y-axis of a histogram?

17 ビュー (過去 30 日間)
Michael 2019 年 11 月 29 日
Answered: Image Analyst 2019 年 11 月 29 日
Let' say that we have 100 data points, and we’re making a histogram.
[counts] = histcounts(data)
sum(counts) should equal to 100.
If I were to normalize the histogram, in other words, we normalize the y-axis, the total count would equal to 1.
Notice here I am not changing the original data, I am simply changing the counts or the y-scale.
Now, I would like to rescale the y-axis, such that the total count would equal 200.
The new plot should follow the same distribution as before, except it has a different y-scale.
Is there a way to do this?

#### 0 件のコメント

サインイン to comment.

### 採用された回答

Star Strider 2019 年 11 月 29 日
One approach:
X = randn(1, 420);
[N,edges] = histcounts(X, 'Normalization', 'probability');
xbar = edges(1:numel(N)) + mean(diff(edges))/2;
figure
bar(xbar, N)
grid
yt = get(gca, 'YTick');
ytix = linspace(min(yt), max(yt), 10);
set(gca, 'YTick',ytix, 'YTickLabel',fix(ytix*200/max(yt)))
Experiment to get different results.

#### 2 件のコメント

Michael 2019 年 11 月 29 日
nice
Star Strider 2019 年 11 月 29 日
Thank you!

サインイン to comment.