Matplotlib.pyplot无法正常工作

时间:2017-01-11 21:08:24

标签: python-3.x ubuntu matplotlib

我在ubuntu上使用python3,我遇到了这个问题:

>>> 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 个答案:

答案 0 :(得分: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()

这会产生预期的情节。

默认情况下,您可以让python使用此功能,方法是在控制台中输入以下内容(或.bashrc文件中):export MPLBACKEND="TkAgg"