How to build a horizontal histogram in MATLAB?

I looked and could not find the answer to this question, so here it goes.

I have some data (a 1 X 1000 vector called data) that I would like to plot for a histogram. If I use the histogram(data) command, then I get a pretty good histogram graph where the x axis is evenly divided into ten buckets (average values โ€‹โ€‹of ten equal intervals between the maximum and minimum data values) and the y-axis records how many times happened for each bucket .

What I really want is the same plot, only with the y axis representing the intervals of the bucket and the x axis representing the counter for each bucket ...

This way, I can insert it in the subtitle next to some other information, and everything will be easier to understand (and look super cool). What is an easy way to do this? Thanks!

+6
source share
2 answers

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

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

enter image description here

Histogram mark

Here is an example showing how to flip a chart along a vertical axis.

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

enter image description here

+9
source

You can also use the normal histogram histogram, and then change the point of view by typing

 >> view(90, -90) 
+2
source

Source: https://habr.com/ru/post/899339/


All Articles