Matplotlib histt​​ype ='stepfilled'故障

时间:2013-05-07 18:28:36

标签: matplotlib histogram

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

matplotlib histogram with histtype='stepfilled' glitches

或者我错过了一些设置?

代码很简单:

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')

顺便说一下。如果我设置histtype='bar',则根本没有任何条形图(尽管如果我没有将yscale设置为'log',它会起作用):

matplotlib histogram with histtype='bar' does not show bars

1 个答案:

答案 0 :(得分:5)

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

此修复程序正在调用ax2.set_yscale('log', nonposy='clip')。 1.2.1中的更改​​是在您致电hist(..., log=True)时自动发生的。如果您正在手动设置比例,则始终需要nonposy='clip'