0

Code:

 np.histogram(df['columnforhistogram'], bins=(np.arange(start=0, stop=2000, step=25)), density=True)
 plt.xlabel("Column")
 plt.ylabel('Bins')
 plt.show()

Output I want:

 I want a histogram with bins starting from 0 , ending at 2000 and at an 
 interval of 25.'
 X-axis should have values 0,25,50 and so on...

Output I am getting

 A blank histogram with values in x-axis from 0 to 1 with interval of 0.2 
 (0,0.2,0.4 ..... 1 on both x - axis and y - axis)
noob
  • 3,601
  • 6
  • 27
  • 73

1 Answers1

1

As far as I can tell np.histogram does not plot a histogram. It simply returns an array of frequencies and an array of edges (check the numpy.histogram documentation ). That's probably why you're getting a blank plot.

You should plt.hist() in order to plot those values before calling plt.show().

hist, bins = np.histogram(df['columnforhistogram'], bins=(np.arange(start=0, stop=2000, step=25)), density=True)
my_hist = plt.hist(hist, bins=bins)
plt.xlabel("Column")
plt.ylabel('Bins')
plt.show()

Alternatively, you could jump straight into pyplot:

_ = plt.plot(df['columnforhistogram'], bins=np.arange(0,2000,25),density=True)
plt.xlabel('Column')
plt.ylabel('Bins')
plt.show()
  • Hi I am getting correct values for x-axis but I would want variable values for y-axis , how to do that – noob Dec 27 '19 at 11:42
  • I am getting values of 2.5, 5.0,7.5 and so on on y-axis. I want variable values on y-axis – noob Dec 27 '19 at 11:46
  • Using this code import matplotlib.pyplot as plt plt.figure(figsize=[10,8]) plt.hist(df['columnforhistogram'], 30, range=[0, 2000], facecolor='gray', align='mid') I am getting a different histogram, with values in bins after 250 as well, however in the above code the higher bins are not showing any values, why is that so_? Any idea? – noob Dec 27 '19 at 11:48