Matplotlib直方图条宽度 [英] Matplotlib histogram bar width
问题描述
我正在使用 matplotlib 直方图 histtype='bar' 将四个数据集绘制在一起.它自动执行的是相对于数据集的大小更改每个数据集的条形宽度.我希望所有四个数据集的条宽都相等.
I am using matplotlib histogram histtype='bar' to plot four datasets together. What it automatically does is that it changes the width of the bar of each dataset relative to the size of the dataset. I want to have equal bar width for all four datasets.
[n, bins, patches = plt.hist(
[np.sort(x2), np.sort(x3), np.sort(x4), np.sort(x5)],
bins=np.logspace(np.log10(8e-8), np.log10(1), 7),
histtype='bar',
weights=[w2,w3,w4,w5],
label=[
'$\Delta {{\chi}^2} <40$',
'$u_0 < 0.045$',
'${s}_{fitted} >5$',
'Multi-peaked'
]
)][1]
推荐答案
每个集合的垃圾箱实际上具有相同的大小(数值),但是您的x轴是对数的,因此看起来像 width 是不同的.尝试在线性 x 轴(不是对数)上绘制单个数据集,您将看到条形的宽度相同.
The bins are actually the same size (numeric value) for each set but your x axis is logarithmic so it looks like the width is different. Try to plot a single dataset in a linear x axis (not logarithmic) and you will see that the widths of the bars are the same.
这篇关于Matplotlib直方图条宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!