我有一个直方图,每个 bin 上有 4 个不同的对象,现在它们彼此堆叠在一起。相反,我需要在同一个直方图 bin 内并排绘制不同的对象(类似于 https://matplotlib.org/3.1.1/gallery/statistics/histogram_multihist.html 中的左上图):
bins=np.logspace(np.log10(0.01),np.log10(20), 11)
plt.hist(a[nosfr]/1e+11, bins, color='red', fill=True, linewidth=2, density=True, histtype='bar', edgecolor='k')
plt.hist(a[highsfr]/1e+11, bins, color='orange', fill=True, linewidth=2, density=True, histtype='bar', edgecolor='k')
plt.hist(b[mynosfr]/1e+11, bins, color='blue', edgecolor='k', fill=True, linewidth=2, density=True, alpha=0.7, histtype='bar')
plt.hist(b[myhighsfr]/1e+11, bins, color='cyan', edgecolor='k', fill=True, linewidth=2, density=True, alpha=0.7, histtype='bar')
plt.xscale('log')
plt.xlim(2e-2, 2e+1)
[nosfr]
、[highsfr]
等在同一样本(a
和 b
)中使用不同的标准绘制对象。我看过的所有例子都与我需要的略有不同,我找不到正确的方法。谢谢!