我正在尝试做一个简单的对数条形图:
import matplotlib.pyplot as plt
plt.bar(range(10), [4**i for i in range(10)], log=True)
plt.show()
它崩溃了:
File "C:\Program Files (x86)\Python33\lib\site-packages\matplotlib\pyplot.py", line 2383, in bar
ret = ax.bar(left, height, width=width, bottom=bottom, **kwargs)
File "C:\Program Files (x86)\Python33\lib\site-packages\matplotlib\axes.py", line 4903, in bar
self.add_patch(r)
File "C:\Program Files (x86)\Python33\lib\site-packages\matplotlib\axes.py", line 1572, in add_patch
self._update_patch_limits(p)
File "C:\Program Files (x86)\Python33\lib\site-packages\matplotlib\axes.py", line 1590, in _update_patch_limits
xys = patch.get_patch_transform().transform(vertices)
File "C:\Program Files (x86)\Python33\lib\site-packages\matplotlib\patches.py", line 582, in get_patch_transform
self._update_patch_transform()
File "C:\Program Files (x86)\Python33\lib\site-packages\matplotlib\patches.py", line 578, in _update_patch_transform
bbox = transforms.Bbox.from_bounds(x, y, width, height)
File "C:\Program Files (x86)\Python33\lib\site-packages\matplotlib\transforms.py", line 786, in from_bounds
return Bbox.from_extents(x0, y0, x0 + width, y0 + height)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
当我使用 log=False 时,它可以工作。我使用 plt.yscale('log'),但随后这些条形消失了。我不明白,在这样一个简单的情况下,我怎么能错误地使用 log 参数。