Normalizing histfit plots to all have the same height of 1

18 次查看(过去 30 天)
Hello,
I have below my code that successfully just plots the fits without the histograms, thanks to another answered question on here. As you can see I am plotting multiple fits onto the same figure, but I want them all to have the same height of ,1 but can't seem to find a direct way to do that from here. Please let me know if you have a solution! I can imagine it isn't that difficult, but I am still learning MATLAB. Thank you!
figure(1)
h70 = histfit(x70, 10000);
set(h70(2), 'color', 'm')
delete(h70(1))
hold on
h90 = histfit(x90, 10000);
set(h90(2), 'color', 'y')
delete(h90(1))
hold on
.
.
.
  1 个评论
Brett Ruben
Brett Ruben 2020-10-11
I have also tried an answer by Star Strider, here is the code and here is the figure it generates. Looks like the Y-axis certainly has changed, but the plots are not peaking at 1.
figure(1)
h70 = histfit(x70, 10000);
set(h70(2), 'color', 'm')
delete(h70(1))
yt70 = get(gca, 'YTick');
set(gca, 'YTick', yt70, 'YTickLabel', yt70/numel(x70))
hold on
h90 = histfit(x90, 10000);
set(h90(2), 'color', 'y')
delete(h90(1))
yt90 = get(gca, 'YTick');
set(gca, 'YTick', yt90, 'YTickLabel', yt90/numel(x90))
hold on
.
.
.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2020-10-11
In a Comment in Getting FWHM from distribution fitter you requested my attention to this.
Try this:
a = randn(1,1E+4); % Create Data
b = randn(1,1E+4)*2; % Create Data
figure
ha = histfit(a,1000);
set(ha(2), 'color','m')
yd = ha(2).YData;
ha(2).YData = ha(2).YData/max(ha(2).YData);
delete(ha(1))
hold on
hb = histfit(b,1000);
set(hb(2), 'color','y')
hb(2).YData = hb(2).YData/max(hb(2).YData);
delete(hb(1))
hold off
.
  3 个评论
Matthew ODonohue
Matthew ODonohue 2022-2-28
Star Strider,
Awesome solution. Thank you so much, seriously. However, what was your motive for defining the variable "yd"? And what is it?
Thank you.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by