如何在同一图上并排显示直方图条形图?

时间:2019-04-09 19:16:10

标签: python histogram

我正在尝试将我的数据与泊松分布进行比较,我需要我的数据和泊松分布都必须是直方图上的条形图。但是,这些条的大小相同,并且泊松分布条在我的数据之上(参见图片)。我该如何做,以使杠铃并排放置?

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')

enter image description here

我加入了

ind = np.arange(n_counts + 1)#组的x个位置

width = 0.35#条形的宽度

现在它给了我这个错误:

enter image description here

0 个答案:

没有答案