我正在試圖用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'
什麼是matplotlib版本。我毫無例外地在1.3.0中運行代碼。順便說一下,隨機數據中有負值,不能在日誌軸上繪製。 – HYRY
哦,我忘了!它是1.3.1。 – stonerichnau