2014-01-09 76 views
0

我正在試圖用Python中的日誌縮放來做一個簡單的繪圖。但我不知道我做錯了什麼,因爲它不會工作。我在Windows 8上使用Python 2.7,Matplotlib 1.3.1。任何人都可以幫忙嗎?Python繪圖和記錄縮放的問題

下面的代碼:

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' 
+0

什麼是matplotlib版本。我毫無例外地在1.3.0中運行代碼。順便說一下,隨機數據中有負值,不能在日誌軸上繪製。 – HYRY

+0

哦,我忘了!它是1.3.1。 – stonerichnau

回答

0

因此,我最終發現了一些關於混合安裝的討論,您在不同的時間添加和升級了安裝,並開始懷疑可能存在一些混合版本問題。然後我卸載了matplotlib並嘗試重新安裝它,並偶然發現了下一個問題:'錯誤:無法找到vcvarsall.bat',並在here中討論了這個問題。於是我不得不安裝MinGW,最後從一開始就重新安裝(也升級了Numpy和Pandas等一些軟件包)整個Python堆棧。在這個過程之後,繪圖問題消失了。

當然這不是問題的真正答案,但至少可以解決它。