Thanks to visit codestin.com
Credit goes to github.com

Skip to content

XKCD style fails except for inline mode #5411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xiaoweiz opened this issue Nov 5, 2015 · 3 comments
Closed

XKCD style fails except for inline mode #5411

xiaoweiz opened this issue Nov 5, 2015 · 3 comments

Comments

@xiaoweiz
Copy link

xiaoweiz commented Nov 5, 2015

OS X El Capitan + Anaconda 2.4 (Python 3.5) + matplotlib 1.4.3

At ipython terminal:

In [1]: import matplotlib.pyplot as plt
In [2]: plt.plot(range(5))
Out[2]: [<matplotlib.lines.Line2D at 0x1085feef0>]
In [3]: plt.show()

This works. However, if I call plt.xkcd(), things fall apart.

In [4]: plt.xkcd()
Out[4]: <matplotlib.rc_context at 0x1097b3d68>

In [5]: plt.plot(range(5))
Out[5]: [<matplotlib.lines.Line2D at 0x10a2eb240>]

In [6]: plt.show()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     57     def draw_wrapper(artist, renderer, *args, **kwargs):
     58         before(artist, renderer)
---> 59         draw(artist, renderer, *args, **kwargs)
     60         after(artist, renderer)
     61

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/figure.py in draw(self, renderer)
   1083         dsu.sort(key=itemgetter(0))
   1084         for zorder, a, func, args in dsu:
-> 1085             func(*args)
   1086
   1087         renderer.close_group('figure')

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     57     def draw_wrapper(artist, renderer, *args, **kwargs):
     58         before(artist, renderer)
---> 59         draw(artist, renderer, *args, **kwargs)
     60         after(artist, renderer)
     61

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2108
   2109         for zorder, a in dsu:
-> 2110             a.draw(renderer)
   2111
   2112         renderer.close_group('axes')

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     57     def draw_wrapper(artist, renderer, *args, **kwargs):
     58         before(artist, renderer)
---> 59         draw(artist, renderer, *args, **kwargs)
     60         after(artist, renderer)
     61

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/lines.py in draw(self, renderer)
    713                 funcname = self.drawStyles.get(self._drawstyle, '_draw_lines')
    714                 drawFunc = getattr(self, funcname)
--> 715                 drawFunc(renderer, gc, tpath, affine.frozen())
    716
    717         if self._marker:

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/lines.py in _draw_lines(self, renderer, gc, path, trans)
   1070
   1071     def _draw_lines(self, renderer, gc, path, trans):
-> 1072         self._lineFunc(renderer, gc, path, trans)
   1073
   1074     def _draw_steps_pre(self, renderer, gc, path, trans):

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/lines.py in _draw_solid(self, renderer, gc, path, trans)
   1110     def _draw_solid(self, renderer, gc, path, trans):
   1111         gc.set_linestyle('solid')
-> 1112         renderer.draw_path(gc, path, trans)
   1113
   1114     def _draw_dashed(self, renderer, gc, path, trans):

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/patheffects.py in draw_path(self, gc, tpath, affine, rgbFace)
    113         for path_effect in self._path_effects:
    114             path_effect.draw_path(self._renderer, gc, tpath, affine,
--> 115                                   rgbFace)
    116
    117     def draw_markers(self, gc, marker_path, marker_trans, path, *args,

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/patheffects.py in draw_path(self, renderer, gc, tpath, affine, rgbFace)
    215     def draw_path(self, renderer, gc, tpath, affine, rgbFace):
    216         Stroke.draw_path(self, renderer, gc, tpath, affine, rgbFace)
--> 217         renderer.draw_path(gc, tpath, affine, rgbFace)
    218
    219

/Users/xiaoweiz/anaconda/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py in draw_path(self, gc, path, transform, rgbFace)
     56             rgbFace = tuple(rgbFace)
     57         linewidth = gc.get_linewidth()
---> 58         gc.draw_path(path, transform, linewidth, rgbFace)
     59
     60     def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):

AttributeError: 'GraphicsContextBase' object has no attribute 'draw_path'

But in jupyter notebook or jupyter qtconsole where %matplotlib inline works, the above issue goes away. Namely, the following works.

import matplotlib.pyplot as plt
%matplotlib inline
plt.xkcd()
plt.plot(range(5))
@jenshnielsen
Copy link
Member

This is likely limited to the OSX backend.

In IPython you can select a different backend with

%matplotlib nameofbackend

i.e. something like

%matplotlib qt

If you have the backend dependencies installed (PyQt etc).

@jenshnielsen
Copy link
Member

I think this is a duplicate of #5049 and fixed in 1.5.0 for me. Can you please check 1.5.0?

@tacaswell
Copy link
Member

Closing as duplicate. @xiaoweiz please ping to have this re-opened if you can reproduce this in 1.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants