使用 matplotlib plt.show() 绘图不可见

2024-03-25

我对 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)

和一个没有白色画布的空图形:

怎么了?我该如何修复它?


如你看到的:

"The Gtk3Agg backend is known to not work on Python 3.x with pycairo."

所以建议提出的是:

Try installing cairocffi.

The installation guide https://pythonhosted.org/cairocffi/overview.html for cairocffi is pretty straight-forward. If the dependencies1 are met it is as simple as:

pip install cairocffi

1) The dependencies for Python 3.x should logically be:

sudo apt-get install python3-dev
sudo apt-get install libffi-dev
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 matplotlib plt.show() 绘图不可见 的相关文章

随机推荐