What you are actually doing is specifying three bins where the first bin is np.min(result)
, second bin is np.max(result)
and third bin is 1
. What you need to do is provide where you want the bins to be located in the histogram, and this must be in increasing order. My guess is that you want to choose bins from np.min(result)
to np.max(result)
. The 1 seems a bit odd, but I'm going to ignore it. Also, you want to plot a 1D histogram of values, yet your input is 2D. If you'd like to plot the distribution of your data over all unique values in 1D, you'll need to unravel your 2D array when using np.histogram
. Use np.ravel
for that.
Now, I'd like to refer you to np.linspace
. You can specify a minimum and maximum value and as many points as you want in between uniformly spaced. So:
bins = np.linspace(start, stop)
The default number of points in between start
and stop
is 50, but you can override this:
bins = np.linspace(start, stop, num=100)
This means that we generate 100 points in between start
and stop
.
As such, try doing this:
import matplotlib.pyplot as plt
import numpy as np
num_bins = 100 # <-- Change here - Specify total number of bins for histogram
plt.hist(result.ravel(), bins=np.linspace(np.min(result), np.max(result), num=num_bins)) #<-- Change here. Note the use of ravel.
plt.show()