我想在我的python脚本中使用matplotlib来显示一些图形。但每当我打电话给它时,我都会收到错误
AttributeError: get_content_extents
MWE:
>>> import matplotlib
>>> from matplotlib import pyplot as plt
>>> def a(x):
... return x*x
...
>>> import numpy as np
>>> d = np.linspace(0, 10, 2**12)
>>> plt.plot(d, a(d))
Gtk-Message: Failed to load module "pantheon-filechooser-module"
[<matplotlib.lines.Line2D object at 0x7f1edc44d350>]
>>> plt.show()
结果是: 回溯(最近一次调用最后一次):
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5agg.py", line 176, in __draw_idle_agg
FigureCanvasAgg.draw(self)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 469, in draw
self.renderer = self.get_renderer(cleared=True)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 486, in get_renderer
self.renderer = RendererAgg(w, h, self.figure.dpi)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 99, in __init__
self._update_methods()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 134, in _update_methods
self.get_content_extents = self._renderer.get_content_extents
AttributeError: get_content_extents
如果我尝试使用
更改后端,也会发生同样的情况plt.switch_backend('qt4agg')
在尝试gtk
后端(&#39; gtkagg&#39;)时,我得到了
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:127: RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK
set_interactive(1)
我该怎么做才能解决这个问题?