matplotlib xkcd在Mac上不起作用 [英] matplotlib xkcd not working on mac

查看:41
本文介绍了matplotlib xkcd在Mac上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在可视化 matplotlib xkcd 图时遇到了一个小问题.通过简单地尝试执行在 matplotlib.org 上找到的示例.当我执行 xkcd.py 时,绘图的可视化不起作用我收到此错误消息:

I've small problem in visualizing matplotlib xkcd plots. By simply trying to execute the example found on matplotlib.org. When i execute xkcd.py the visualization of the plots does't work and I get this error message:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/figure.py", line 1084, in draw
    func(*args)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/axes/_base.py", line 2092, in draw
    a.draw(renderer)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/lines.py", line 712, in draw
    drawFunc(renderer, gc, tpath, affine.frozen())
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/lines.py", line 1067, in _draw_lines
    self._lineFunc(renderer, gc, path, trans)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/lines.py", line 1107, in _draw_solid
    renderer.draw_path(gc, path, trans)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/patheffects.py", line 115, in draw_path
    rgbFace)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/patheffects.py", line 217, in draw_path
    renderer.draw_path(gc, tpath, affine, rgbFace)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/backends/backend_macosx.py", line 58, in draw_path
    gc.draw_path(path, transform, linewidth, rgbFace)
AttributeError: 'GraphicsContextBase' object has no attribute 'draw_path'
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/figure.py", line 1084, in draw
    func(*args)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/axes/_base.py", line 2092, in draw
    a.draw(renderer)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/axis.py", line 1102, in draw
    tick.draw(renderer)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/axis.py", line 244, in draw
    self.tick1line.draw(renderer)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/lines.py", line 757, in draw
    rgbaFace)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/patheffects.py", line 127, in draw_markers
    **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/backend_bases.py", line 266, in draw_markers
    rgbFace)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/patheffects.py", line 115, in draw_path
    rgbFace)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/patheffects.py", line 217, in draw_path
    renderer.draw_path(gc, tpath, affine, rgbFace)
  File "/Library/Python/2.7/site-packages/matplotlib-1.5.x-py2.7-macosx-10.10-intel.egg/matplotlib/backends/backend_macosx.py", line 58, in draw_path
    gc.draw_path(path, transform, linewidth, rgbFace)
AttributeError: 'GraphicsContextBase' object has no attribute 'draw_path'

虽然如果我尝试保存这些图,我会得到两个完美的 png 文件:

While if I try to save these plots I get two perfect png files:

我真的不明白为什么!

推荐答案

正如评论者所说,不支持macOSX后端.使用OS X 10.10.1上的Python 3.4,TkAgg起作用了.

As a commenter said, the macOSX backend isn't supported. With Python 3.4 on OS X 10.10.1, TkAgg worked.

import matplotlib
matplotlib.use("TkAgg")

这篇关于matplotlib xkcd在Mac上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆