Matplotlib直方图条宽度 [英] Matplotlib histogram bar width

查看:43
本文介绍了Matplotlib直方图条宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 matplotlib 直方图 histt​​ype='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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆