Matplotlib histt​​ype ='stepfilled'故障

tam*_*gal 1 matplotlib histogram

我正在绘制一些直方图并且遇到麻烦histtype=stepfilled.填充曲线显然有一些错误的锚点:

matplotlib直方图与histt​​ype ='stepfilled'故障

或者我错过了一些设置?

代码很简单:

ax2 = fig.add_subplot(212)
ax2.hist(self._neutrinoEnergies, histtype='stepfilled', color=colors.pop())
ax2.set_title(r'Neutrino Energies')
ax2.set_xlabel(r'$E_\nu$')
ax2.set_ylabel('count')
ax2.set_yscale('log')
Run Code Online (Sandbox Code Playgroud)

顺便说一句.如果我设置histtype='bar',根本没有任何条形图(虽然如果我没有设置yscale,它会起作用'log'):

带有histt​​ype ='bar'的matplotlib直方图不显示条形图

小智 5

Matplotlib试图一直填充到0,但0总是在对数刻度上偏离轴(因为log(0)是负无穷大).

修复是在调用ax2.set_yscale('log', nonposy='clip').1.2.1中的更改​​是这样的,当您打电话时会自动发生这种情况hist(..., log=True).如果你正在手动设置比例,你总是需要nonposy='clip'.