我是Python和Linux的新手,我需要帮助,我尝试使用matplotlib以下列方式显示简单的情节:
from matplotlib import pyplot as plt
plt.plot([5,6,7,8], [7,3,8,3])
plt.show()
但是,当我运行python3 test.py
时,我得到以下输出:
/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. "
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3.py:215: Warning: Source ID 7 was not found when attempting to remove it
GLib.source_remove(self._idle_event_id)
和没有白色画布的空图:
有什么问题?我该如何解决?
答案 0 :(得分:15)
如你所见:
"The Gtk3Agg backend is known to not work on Python 3.x with pycairo."
因此提出的 建议 是:
Try installing cairocffi.
cairocffi
的{{3}}非常简单。如果满足依赖 1 ,则只需:
pip install cairocffi
1)Python 3.x
的依赖关系 逻辑上应为:
sudo apt-get install python3-dev
sudo apt-get install libffi-dev