confused
confused

Reputation: 3

Why is my matplotlib.pyplot.hist not binning my data

I am attempting to create a histogram out of an array I made. When I plot the histogram it does not plot like a regular histogram it just gives me lines where my data points are.

I have attempted to set bins = [0,10,20,30,40,50,60,70,80,90] including with 0 and 100 on the ends. I've tried bins = range() and bins= 'auto'

array2 = np.random.uniform(10.0,100.0,size=(1,100))                                        
#create a random array uniformly distributed between 1 and 100
print array2

plt.hist(array2)                                                              
#print a histogram
plt.title('Histogram of a Uniformly Distributed Sample between 10 and 
100')
plt.xlim(0,100)
plt.show()

I'm really new and I'm not sure how to paste pictures. The plot is just a bunch of vertical lines at the data points instead of a binned histogram. Or sometimes with some of the choices I make for bins = I end up with a complete blank plot. I woul like to appologize if this has been dealt with before I have not been able to find any previous questions that gave me help.

Upvotes: 0

Views: 1277

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339112

You create a 2D array with one row and 100 columns. Hence you get 100 histograms, each with one bin.

Use a 1D vector of data instead.

array2 = np.random.uniform(10.0,100.0,size=100)           

Upvotes: 1

Related Questions