Normalizing histfit plots to all have the same height of 1

4 views (last 30 days)
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 Comment
Brett Ruben
Brett Ruben on 11 Oct 2020
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
.
.
.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 11 Oct 2020
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 Comments
Star Strider
Star Strider on 12 Oct 2020
I very much appreciate your compliment!
As always, my pleasure!
Matthew ODonohue
Matthew ODonohue on 28 Feb 2022
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!