How to create a horizontal histfit plot?

4 views (last 30 days)
Dear mathworks community,
I would like to plot my data as a horizontal histogram with fitted gaussian. However, I have encountered a problem. I plotted my data using:
h = histfit(data)
Then, I wanted to change the orientation of the plot. I was able to do it for the histogram using:
h(1).Horizontal = 'on'
However, there seem not to be a 'Horizontal' option for the fitted gaussian. Indeed, when I run get(h(2)), I didn't see an 'Orientation' or a 'Horizontal' property. Of course, a histfit plot with horizontal histogram and vertical fitted gaussian is meaningless.
Is there a way to resolve this issue? I will be very grateful for your help. Kasia

Answers (1)

Star Strider
Star Strider on 16 May 2018
Try this:
h = histfit(data);
h(1).Horizontal = 'on';
Hy = h(2).XData;
Hx = h(2).YData;
h(2).Visible = 'off';
hold on
plot(Hx, Hy, 'LineWidth',2)
hold off

Community Treasure Hunt

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

Start Hunting!