Posts

Showing posts from December 24, 2018

Creating a histogram that sorts array values into bins, and shows the the frequency of items in the bins

Image
0 For an array of values between 0 and 1, I want to create a histogram of 5 bins where bin one show the frequency(# of times) numbers between 0-0.2 show up in the array, bin 2 shows the frequency of numbers between 0.2-0.4, bin 3 is 0.4-0.6, bin 4: 0.6-0.8, bin 5 0.8-1. import numpy as np arr = np.array([0.5, 0.1, 0.05, 0.67, 0.8, 0.9, 1, 0.22, 0.25]) y, other_stuff = np.histogram(arr, bins=5) x = range(0,5) graph = plt.bar(x,height=y) plt.show() python arrays numpy matplotlib histogram share | improve this question edited Nov 21 at 1:10 eyllanesc 72.8k 9 30 55