2017-01-11 63 views
-3

我使用Ubuntu的python3,我有這樣的問題:Matplotlib.pyplot不工作

>>> import matplotlib.pyplot as plt 
/usr/local/lib/python3.4/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. 
    warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.') 
/usr/local/lib/python3.4/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. 
    warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.') 
/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py:18: UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo. Try installing cairocffi. 
    "The Gtk3Agg backend is known to not work on Python 3.x with pycairo. " 

我怎樣才能解決這個問題?

+1

你真的*讀過*錯誤嗎?它告訴你到底該做什麼。使用Google搜索警告可以爲您提供更多關於它們的信息。至少*嘗試*在問這裏之前自己解決問題。 – MattDMo

+0

「已知Gtk3Agg後端無法在Pycairo上使用Python 3.x,請嘗試安裝cairocffi」。你嘗試過嗎? – tom

回答

1

您可能想要查看的Gtk3Agg後端的替代方法是Tinker。舉個例子:(使用Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux

import matplotlib 
matplotlib.use('TkAgg') 
import matplotlib.pyplot as plt 
plt.plot(range(10)) 
plt.show() 

這產生了預期的情節。

通過在控制檯中輸入以下內容(或.bashrc文件),可以使python默認使用它:export MPLBACKEND="TkAgg"