Matplotlib xkcd not working on mac

I have a little problem rendering matplotlib xkcd plots. Just try following the example found on matplotlib.org . When I execute xkcd.py, the graph rendering does not work and I receive 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'

      

While trying to save these plots, I end up with two perfect png files:

I really don't understand why!

+3


source to share


1 answer


As the commenter said, macOSX backend is not supported. With Python 3.4 on OS X 10.10.1, TkAgg worked.



import matplotlib
matplotlib.use("TkAgg")

      

+3


source







All Articles