Switch X and Y axis in a histogram

58 ビュー (過去 30 日間)
Chen Zhu
Chen Zhu 2017 年 4 月 10 日
回答済み: Steven Lord 2017 年 4 月 10 日
hist(a)
How to switch the X and Y axis? Currently X represents values, and Y represents the number of elements in that range. I want to switch the X and Y axis, letting X axis represents the number of elements in that range.
Thanks!

回答 (2 件)

Steven Lord
Steven Lord 2017 年 4 月 10 日
Change the histogram object's Orientation property.
x = randn(1, 1e4);
h = histogram(x, 'Orientation', 'vertical');
disp('Press a key to change the orientation')
pause
h.Orientation = 'horizontal';

Star Strider
Star Strider 2017 年 4 月 10 日
See if the barh (link) function will do what you want.
You will have to use histcounts with it to get the counts and bin edges. Since barh wants the bin centres, one way to calculate them is to take the mean of the difference of the regularly-spaced edges, divide it by 2, and added it to all but the highest bin edge.
Example:
edges = 1:5;
centres = mean(diff(edges))/2 + edges(1:end-1);

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by