在Python 3 pylab中使用Matplotlib进行绘图:Tkinter和Qt FontManager错误

亚瑟

我正在尝试$ ipython3 --pylab在Ubuntu 14.04的Python 3中使用pylab(即)。无论使用Tkinter还是Qt4后端,我都遇到相同的错误。

AttributeError: 'FontManager' object has no attribute 'ttf_lookup_cache'

但是,相同的基本绘图例程(plt.plot([1,2,3,4]))在Python 2 pylab中有效。

据我所知,我已经安装了必要的依赖项(注意,对于Python 2和Python 3):

sudo apt-get install python-numpy python-scipy python-matplotlib
sudo apt-get install python3-numpy python3-scipy python3-matplotlib
sudo apt-get install python-tk python3-tk
sudo apt-get install libqt4gui libqt4core python-qt4 python3-qt4

完整的追溯可在下面找到。这是Tkinter的:

$ ipython3 --matplotlib tk
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
Type "copyright", "credits" or "license" for more information.

IPython 1.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import matplotlib.pyplot as plt

In [2]: plt.plot([1,2,3,4])
Out[2]: [<matplotlib.lines.Line2D at 0x7f1496dc9c50>]

In [3]: Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1490, in __call__
    return self.func(*args)
  File "/usr/lib/python3.4/tkinter/__init__.py", line 535, in callit
    func(*args)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 363, in idle_draw
    self.draw()
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 348, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 451, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1035, in draw
    func(*args)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axes.py", line 2088, in draw
    a.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1094, in draw
    renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1043, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/text.py", line 755, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/text.py", line 321, in _get_layout
    ismath=False)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 214, in get_text_width_height_descent
    font = self._get_agg_font(prop)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 258, in _get_agg_font
    fname = findfont(prop)
  File "/usr/lib/python3/dist-packages/matplotlib/font_manager.py", line 1362, in findfont
    font = fontManager.findfont(prop, **kw)
  File "/usr/lib/python3/dist-packages/matplotlib/font_manager.py", line 1202, in findfont
    font_cache = self.ttf_lookup_cache
AttributeError: 'FontManager' object has no attribute 'ttf_lookup_cache'

这是Qt / Qt4:

$ ipython3 --matplotlib qt
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
Type "copyright", "credits" or "license" for more information.

IPython 1.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import matplotlib.pyplot as plt

In [2]: plt.plot([1,2,3,4])
Out[2]: [<matplotlib.lines.Line2D at 0x7f0f840947f0>]

In [3]: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_qt4.py", line 374, in idle_draw
    self.draw()
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_qt4agg.py", line 154, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 451, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1035, in draw
    func(*args)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axes.py", line 2088, in draw
    a.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1094, in draw
    renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1043, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/text.py", line 755, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/text.py", line 321, in _get_layout
    ismath=False)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 214, in get_text_width_height_descent
    font = self._get_agg_font(prop)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 258, in _get_agg_font
    fname = findfont(prop)
  File "/usr/lib/python3/dist-packages/matplotlib/font_manager.py", line 1362, in findfont
    font = fontManager.findfont(prop, **kw)
  File "/usr/lib/python3/dist-packages/matplotlib/font_manager.py", line 1202, in findfont
    font_cache = self.ttf_lookup_cache
AttributeError: 'FontManager' object has no attribute 'ttf_lookup_cache'

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

在这两种情况下,都会出现绘图窗口。在Tkinter的情况下,该图为空白(空),但是使用Qt4时,我的确看到了正确的结果-而且错误仍然会触发。同样,这在Python 2.7中的任何后端都可以正常工作。我想念什么?

亚瑟

通过删除matplotlib字体缓存(Python 3和Python 2字体缓存),我能够解决此问题,例如,

rm /home/arthur/.cache/matplotlib/fontList*.cache

现在,我可以使用其他任何以下环境初始化,而不会出现错误:

ipython3 --pylab
ipython3 --matplotlib tk
ipython3 --matplotlib qt4

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用滑块进行错误绘图(python matplotlib)

来自分类Dev

在python中使用matplotlib进行相似性度量的绘图圆中的错误

来自分类Dev

在Python 3和Matplotlib中使用带有字符串的格式的无效语法错误

来自分类Dev

Python 3 - Tkinter 名称错误

来自分类Dev

python 3,tkinter NonType 错误

来自分类Dev

在 Python 3 中使用 Socket 获取 400 错误请求错误

来自分类Dev

在Python 3和tkinter中使用变量调用函数

来自分类Dev

在Python 3和tkinter中使用变量调用函数

来自分类Dev

使用Python中的错误栏进行绘图

来自分类Dev

用numpy分隔数组以在python中使用matplotlib进行绘图

来自分类Dev

用numpy分隔数组以在python中使用matplotlib进行绘图

来自分类Dev

Python3、Tkinter、SQLite3 - 登录编码错误

来自分类Dev

python3和opencv错误

来自分类Dev

EOF错误python 3?

来自分类Dev

尝试使用 reddit api 和 python 3 进行身份验证时出现 401 错误

来自分类Dev

Python的Matplotlib绘图顺序错误

来自分类Dev

Python 2 和 Python 3 与虚拟环境混合错误?

来自分类Dev

通过在python 3和tkinter中使用colorchooser更改tkinter窗口中文本的颜色

来自分类Dev

在Ubuntu 12.04上使用Pylab的Python 3

来自分类Dev

在Ubuntu 12.04上使用Pylab的Python 3

来自分类Dev

Python 3 使用装饰器生成错误与 Python 2

来自分类Dev

Python 3 tkinter。如何修复此 Tcl 网格错误?

来自分类Dev

使用Matplotlib进行实时绘图的Python

来自分类Dev

在Matplotlib中使用Python的日期时间错误

来自分类Dev

在Python 2和Python 3中使用“ + =”与“ extend”进行串联

来自分类Dev

在Python 3中导入错误,但可在Python 2中使用

来自分类Dev

使用Matplotlib在Python中使用两个不同的Y轴进行绘图

来自分类Dev

无法在python中使用plotly进行绘图

来自分类Dev

在Pandas / Python中使用GroupBy进行绘图

Related 相关文章

  1. 1

    使用滑块进行错误绘图(python matplotlib)

  2. 2

    在python中使用matplotlib进行相似性度量的绘图圆中的错误

  3. 3

    在Python 3和Matplotlib中使用带有字符串的格式的无效语法错误

  4. 4

    Python 3 - Tkinter 名称错误

  5. 5

    python 3,tkinter NonType 错误

  6. 6

    在 Python 3 中使用 Socket 获取 400 错误请求错误

  7. 7

    在Python 3和tkinter中使用变量调用函数

  8. 8

    在Python 3和tkinter中使用变量调用函数

  9. 9

    使用Python中的错误栏进行绘图

  10. 10

    用numpy分隔数组以在python中使用matplotlib进行绘图

  11. 11

    用numpy分隔数组以在python中使用matplotlib进行绘图

  12. 12

    Python3、Tkinter、SQLite3 - 登录编码错误

  13. 13

    python3和opencv错误

  14. 14

    EOF错误python 3?

  15. 15

    尝试使用 reddit api 和 python 3 进行身份验证时出现 401 错误

  16. 16

    Python的Matplotlib绘图顺序错误

  17. 17

    Python 2 和 Python 3 与虚拟环境混合错误?

  18. 18

    通过在python 3和tkinter中使用colorchooser更改tkinter窗口中文本的颜色

  19. 19

    在Ubuntu 12.04上使用Pylab的Python 3

  20. 20

    在Ubuntu 12.04上使用Pylab的Python 3

  21. 21

    Python 3 使用装饰器生成错误与 Python 2

  22. 22

    Python 3 tkinter。如何修复此 Tcl 网格错误?

  23. 23

    使用Matplotlib进行实时绘图的Python

  24. 24

    在Matplotlib中使用Python的日期时间错误

  25. 25

    在Python 2和Python 3中使用“ + =”与“ extend”进行串联

  26. 26

    在Python 3中导入错误,但可在Python 2中使用

  27. 27

    使用Matplotlib在Python中使用两个不同的Y轴进行绘图

  28. 28

    无法在python中使用plotly进行绘图

  29. 29

    在Pandas / Python中使用GroupBy进行绘图

热门标签

归档