I have two numpy arrays X
and GX
(float and int respectively) and I want to bin the X
array (and thus corresponding GX
values which saves the frequency) and plot a histogram with bins on x-axis and frequency on the y-axis. I have tried using pandas' qcut
, cut
and matplotlib's histogram
as well. None of them seems to work. I have created bins and frequencies with numpy from scratch but all I can get is a scatter plot.
bins = np.linspace(min(X), max(X),100)
freq = []
countl = 0
for i in range(len(bins)-1):
count = 0
for j in range(len(X)):
if bins[i]<X[j]<bins[i+1]:
count += np.sum(GX[np.where(X==X[j])])
freq.append(count)
for j in X:
if bins[-2]<j<bins[-1]:
countl += np.sum(GX[np.where(X==j)])
freq.append(countl)
plt.figure(figsize=(7,7))
plt.scatter(bins,freq,c='b')
Instead of the scatterplot, how can I get the bar graph or histogram (and probably a better method to bin values)?