Python 空条形图matplotlib

Python 空条形图matplotlib,python,matplotlib,histogram,Python,Matplotlib,Histogram,我正在尝试使用以下两个数组创建条形图-xbinmids作为x坐标,xbinned_ms作为条形图的高度 xbinned_ms: [6.28e-16, 0, 0, 0, 0, 0, 6.28e-16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.28e-16] xbinmids:

我正在尝试使用以下两个数组创建条形图-xbinmids作为x坐标,xbinned_ms作为条形图的高度

xbinned_ms:  [6.28e-16, 0, 0, 0, 0, 0, 6.28e-16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.28e-16]

xbinmids:  [1.9869553456140592e-26, 5.960866036842178e-26, 9.934776728070296e-26, 1.3908687419298414e-25, 1.7882598110526532e-25, 2.185650880175465e-25, 2.583041949298277e-25, 2.9804330184210885e-25, 3.377824087543901e-25, 3.7752151566667126e-25, 4.172606225789524e-25, 4.569997294912336e-25, 4.967388364035148e-25, 5.36477943315796e-25, 5.762170502280771e-25, 6.159561571403584e-25, 6.556952640526395e-25, 6.954343709649207e-25, 7.351734778772019e-25, 7.749125847894831e-25, 8.146516917017643e-25, 8.543907986140454e-25, 8.941299055263266e-25, 9.338690124386079e-25, 9.73608119350889e-25, 1.0133472262631701e-24, 1.0530863331754513e-24, 1.0928254400877326e-24, 1.1325645470000137e-24, 1.1723036539122949e-24, 1.2120427608245762e-24, 1.2517818677368573e-24, 1.2915209746491384e-24, 1.3312600815614196e-24, 1.3709991884737009e-24, 1.410738295385982e-24, 1.4504774022982631e-24, 1.4902165092105445e-24, 1.5299556161228256e-24, 1.5696947230351067e-24, 1.6094338299473879e-24, 1.6491729368596692e-24, 1.6889120437719503e-24, 1.7286511506842314e-24, 1.7683902575965126e-24, 1.8081293645087937e-24, 1.8478684714210752e-24, 1.8876075783333563e-24, 1.9273466852456375e-24, 1.9670857921579186e-24, 2.0068248990701997e-24]
当我使用以下方法绘制这些阵列时:

xlow = 0
xhigh = 2.0068248990701997e-24
figMassxHist = plt.figure()
axMassxHist = plt.axes()
axMassxHist.set_xlim([xlow, xhigh])
plt.ticklabel_format(style='sci', axis='x', scilimits=(0, 0))

plt.bar(xbinmids, xbinned_ms, align='center')
生成的条形图为空。我想可能是因为这些条太细,看不见,所以尝试使用以下方法保存绘图:

plt.savefig(gdir + "/m_x_pp.eps", format='eps', dpi = 72*5)

但结果仍然是空的。如何创建此数据的非空条形图?

我不确定是否可以根据您的数据绘制条形图,但可以使用散点图等其他图形(请参见下面的代码)。希望一切顺利:

import matplotlib.pyplot as plt

xbinned_ms =  [6.28e-16, 0, 0, 0, 0, 0, 6.28e-16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.28e-16]

xbinmids = [1.9869553456140592e-26, 5.960866036842178e-26, 9.934776728070296e-26, 1.3908687419298414e-25, 1.7882598110526532e-25, 2.185650880175465e-25, 2.583041949298277e-25, 2.9804330184210885e-25, 3.377824087543901e-25, 3.7752151566667126e-25, 4.172606225789524e-25, 4.569997294912336e-25, 4.967388364035148e-25, 5.36477943315796e-25, 5.762170502280771e-25, 6.159561571403584e-25, 6.556952640526395e-25, 6.954343709649207e-25, 7.351734778772019e-25, 7.749125847894831e-25, 8.146516917017643e-25, 8.543907986140454e-25, 8.941299055263266e-25, 9.338690124386079e-25, 9.73608119350889e-25, 1.0133472262631701e-24, 1.0530863331754513e-24, 1.0928254400877326e-24, 1.1325645470000137e-24, 1.1723036539122949e-24, 1.2120427608245762e-24, 1.2517818677368573e-24, 1.2915209746491384e-24, 1.3312600815614196e-24, 1.3709991884737009e-24, 1.410738295385982e-24, 1.4504774022982631e-24, 1.4902165092105445e-24, 1.5299556161228256e-24, 1.5696947230351067e-24, 1.6094338299473879e-24, 1.6491729368596692e-24, 1.6889120437719503e-24, 1.7286511506842314e-24, 1.7683902575965126e-24, 1.8081293645087937e-24, 1.8478684714210752e-24, 1.8876075783333563e-24, 1.9273466852456375e-24, 1.9670857921579186e-24, 2.0068248990701997e-24]

plt.scatter(xbinmids, xbinned_ms)

plt.show()

plt.savefig(gdir + "/m_x_pp.eps", format='eps', dpi = 72*5)
希望这有帮助!:

plt.bar有一个宽度参数,可以是所有条的单个宽度,也可以是每个条的宽度数组。在这种情况下,可以使用前两个x值之间的差值,因为所有箱子似乎都具有相同的宽度。如果你需要一个小的酒吧之间的差距,你可以乘以0.8左右的数字

当高度非常小时,plt.bar似乎做错了什么。ylims将它们设置在-1e12和1e12之间,使它们看起来太小而看不见。此错误可通过明确设置y限制来解决:

将matplotlib.pyplot作为plt导入 xbinned_ms=[6.28e-16,0,0,0,0,0,6.28e-16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.28e-16] xbinmids=9.9347767280702966E-26,1.390868741419298414141414141414141414141414141414141414 E-26,1.39086868686868741414141414141414141414141414141414141414141414141414141414141414141414141414141414 E-25,1.1.1.78989898984141414141414141414141414141414141414141414141414141414141414141414141414141414 E-25,1-26,1-26,1-26,1-26,1.9-26,1.9-26,1.9-26,1.9-26,1.9-26,1.9-26,1.9-26,1.9-26,1.9-26,1.9-26,1.1.9.9 502280771E-25,7.351734777777 7-259,9.73736041414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141417-25,7.7.7.3573737373737373734778787877777777777777777777777777777 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7啊,,1.2915209747474913844E-24,1.3313226008156414141414141414196E-24,1.331.331268686864141564141414141414141414141414141414141414141414141414141414141414141414141414196E-24,1.331.3312626008-414141414141414141416,1.3799999999414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141412575965126e-24、1.8081293645087937e-24、1.8478684714210752e-24、1.8876075783333563e-24、1.9273466852456375e-24、1.96708579215799186E-24、2.0068248990701997e-24] plt.barxbinmids,xbinned_ms,宽度=xbinmids[1]-xbinmids[0],ec='k',lw=1 plt.xlabel'bins' plt.ylabel'ms' plt.ylim0,maxxbinned_ms*1.1 节目
条形图是比较模拟结果和实验数据所必需的。不幸的是,其他类型的图形,如散点图或stem图,没有那么有用。我知道Python会像我一样在输入两个数组时为条形图创建默认宽度0.8,但对于我尝试的范围内的条形图数量来说,这似乎太窄了这个答案有用吗?