I am trying to compare my data with a poisson distribution, I need both my data and the poisson distribution to be bars on a histogram. However, the bars are the same size and the poisson distribution bars are on top of my data (see picture). How do I make it so the bars are side by side?
import math
import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import poisson
n_counts = np.arange(10)
f_measured = np.array([45,54,55,24,14,7,1]) # How often count occured
f_mean = np.sum(f_measured*n_counts) / np.sum(f_measured)
f_poisson = poisson.pmf(n_counts,f_mean) # Poisson distribution
f_poisson = f_poisson * f_measured.sum() # Normalize to total number of trials
plt.bar(n_counts,f_measured,color = 'b')
plt.xlabel('Number of Counts')
plt.ylabel('Frequency')
ind = np.arange(n_counts+1) # the x locations for the groups
width = 0.35 # the width of the bars
f_poisson = poisson.pmf(n_counts,f_mean) # Poisson distribution
f_poisson = f_poisson * f_measured.sum()
plt.bar(n_counts,f_poisson,color='r')
I added in
ind = np.arange(n_counts+1) # the x locations for the groups
width = 0.35 # the width of the bars
and now it gives me this error: