使用matplotlib plt.show()不可见图 [英] Plots are not visible using matplotlib plt.show()
本文介绍了使用matplotlib plt.show()不可见图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我真的是Python和Linux的新手,我需要帮助,我尝试使用matplotlib通过以下方式显示简单绘图:
I'm really new in Python and Linux and I need help, I tried to use matplotlib for showing a simple plot in the following way:
from matplotlib import pyplot as plt
plt.plot([5,6,7,8], [7,3,8,3])
plt.show()
但是,当我运行 python3 test.py
时,我得到以下输出:
But, when I run python3 test.py
, I get the following output:
/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)
和一个没有白色画布的空图:
and an empty figure without white canvas:
怎么了?我该如何解决?
What is wrong? How can I fix it?
推荐答案
如您所见:
"The Gtk3Agg backend is known to not work on Python 3.x with pycairo."
所以建议是:
And so the suggestion presented is:
Try installing cairocffi.
cairocffi
安装指南>非常简单.如果满足依赖关系1,则很简单:
pip install cairocffi
<小时>
1) Python 3.x
应该 的依存关系在逻辑上为:
sudo apt-get install python3-dev
sudo apt-get install libffi-dev
这篇关于使用matplotlib plt.show()不可见图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文