如何在MATLAB中绘制水平直方图?

时间:2022-01-28 21:19:26

I looked and couldn't find an answer for this question, so here goes.

我看了看,找不到这个问题的答案,所以就这样。

I have some data (a 1 X 1000 vector called data) that I would like to plot the histogram information for. If I use the histogram(data) command then I get a nice enough histogram plot where the x-axis is the divided evenly into ten buckets (midpoint values of the ten equal intervals between the max and min values of the data) and the y-axis records how many occurances occured for each bucket.

我有一些数据(一个1x1000的矢量叫做data)我想要绘制直方图信息。如果我使用直方图(数据)命令然后我得到一个好足够的直方图绘制轴的均匀分成十桶(中间值的十个相等间隔的最大和最小值之间的数据)和y轴记录多少每个桶的情形发生。

What I really want is the same plot, just with the y-axis representing the bucket intervals, and the x-axis representing the count for each bucket...

我真正想要的是同样的图,y轴表示桶间隔,x轴表示每个桶的计数……

That way I can stick it into a subplot next to some other information, and everything will be easier to understand (and look super cool). What's an easy way to accomplish this? Thanks!

这样,我就可以把它插入到其他信息旁边的子情节中,一切都更容易理解(而且看起来超级酷)。有什么简单的方法可以做到这一点?谢谢!

3 个解决方案

#1


9  

You can achieve what you want using the barh function. Here's an example:

您可以使用barh函数实现所需的内容。这里有一个例子:

testData = randn(10000,1); %# test data
[counts,bins] = hist(testData); %# get counts and bin locations
barh(bins,counts)

如何在MATLAB中绘制水平直方图?

Flipping the bar chart

Here's an example showing how to flip the chart along a vertical axis.

下面的示例展示了如何沿着垂直轴翻转图表。

h=barh(bins,counts); %# include previous two lines from above
set(get(h,'Parent'),'xdir','r')

如何在MATLAB中绘制水平直方图?

#2


3  

You can also use the regular histogram function hist and then change the point of view by typing

您还可以使用常规的直方图函数hist,然后通过输入来更改视图

>> view(90, -90)

#3


1  

since the HISTOGRAM function was introduced (R2014b), you can make a horizontal histogram by setting 'orientation' to 'horizontal'

由于直方图功能被引入(R2014b),您可以通过设置“定向”到“水平”来做水平直方图。

example:

例子:

histogram(data,'orientation','horizontal')

#1


9  

You can achieve what you want using the barh function. Here's an example:

您可以使用barh函数实现所需的内容。这里有一个例子:

testData = randn(10000,1); %# test data
[counts,bins] = hist(testData); %# get counts and bin locations
barh(bins,counts)

如何在MATLAB中绘制水平直方图?

Flipping the bar chart

Here's an example showing how to flip the chart along a vertical axis.

下面的示例展示了如何沿着垂直轴翻转图表。

h=barh(bins,counts); %# include previous two lines from above
set(get(h,'Parent'),'xdir','r')

如何在MATLAB中绘制水平直方图?

#2


3  

You can also use the regular histogram function hist and then change the point of view by typing

您还可以使用常规的直方图函数hist,然后通过输入来更改视图

>> view(90, -90)

#3


1  

since the HISTOGRAM function was introduced (R2014b), you can make a horizontal histogram by setting 'orientation' to 'horizontal'

由于直方图功能被引入(R2014b),您可以通过设置“定向”到“水平”来做水平直方图。

example:

例子:

histogram(data,'orientation','horizontal')