Python绘图和logscaling的问题

时间:2014-01-09 01:27:24

标签: python-2.7 matplotlib

我正在尝试使用Python中的日志缩放进行简单的绘图。但我不知道我做错了什么,因为它不起作用。我在Windows 8,Matplotlib 1.3.1上使用Python 2.7。有人可以帮忙吗?

以下是代码:

df = pd.DataFrame(np.random.randn(100, 5)*1000000)

plt.yscale('log')
plt.plot(df)  

或:

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.semilogy(df)

或:

df.plot(logy=True)

但无论我怎么做,我总是以下面的错误信息结束:

In [7]: Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 495, in callit
func(*args)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 363, in        idle_draw
self.draw()
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 348, in draw
FigureCanvasAgg.draw(self)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 451, in draw
self.figure.draw(self.renderer)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1034, in draw
func(*args)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 2086, in draw
a.draw(renderer)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axis.py", line 1093, in draw
renderer)
File "C:\Python27\lib\site-packages\matplotlib\axis.py", line 1042, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "C:\Python27\lib\site-packages\matplotlib\text.py", line 754, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "C:\Python27\lib\site-packages\matplotlib\text.py", line 329, in _get_layout
ismath=ismath)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 210, in get_text_width_height_descent
self.mathtext_parser.parse(s, self.dpi, prop)
File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 3009, in parse
self.__class__._parser = Parser()
File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 2193, in __init__
- ((lbrace + float_literal + rbrace)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

2 个答案:

答案 0 :(得分:0)

这看起来可能是一个已知的错误。见https://github.com/matplotlib/matplotlib/pull/2338

答案 1 :(得分:0)

所以我终于找到了一些关于混合安装的讨论,你在不同的时间添加和升级了你的安装,并开始怀疑可能存在一些混合版本的问题。然后我卸载了matplotlib并尝试重新安装它并偶然发现了下一个问题:'错误:无法找到vcvarsall.bat'并在here中对此进行了一些讨论。所以我不得不安装MinGW,最后从头开始重新安装(并且还升级了一些像Numpy和Pandas这样的软件包)。在这个过程之后,绘图问题就消失了。

当然,这不是问题的真正答案,但至少它已经解决了。