0

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.

4
  • I have tried that as well. Commented Sep 12, 2019 at 3:05
  • Could you show an image of the result? Commented Sep 12, 2019 at 3:06
  • Try a bigger size. Your x range and number of datapoints are close together. Commented Sep 12, 2019 at 3:11
  • It turns out I accidentally made a 2D array when I meant to make a 1D array. I can't post pics yet or I would have. Thanks for the help. Commented Sep 12, 2019 at 3:19

1 Answer 1

1

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)           
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so very much. I hadn't even thought to look at my array. This fixed my issue right up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.