How to create a horizontal histfit plot?

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

回答(1 个)

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

类别

帮助中心File Exchange 中查找有关 Descriptive Statistics and Visualization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by