Skip to content

Loading…

WebAgg: pylab compatibility #1651

Merged
merged 1 commit into from

3 participants

@mdboom
Matplotlib Developers member

Fixes #1638 in a temporary way so that WebAgg works with ipython --pylab. Once the IPython side of the integration is complete, this will probably no longer be necessary.

@pelson pelson commented on the diff
lib/matplotlib/backend_bases.py
@@ -100,6 +101,10 @@ def __call__(self, block=None):
# IPython versions >= 0.10 tack the _needmain
# attribute onto pyplot.show, and always set
# it to False, when in --pylab mode.
+ ipython_pylab = ipython_pylab and get_backend() != 'WebAgg'
+ # TODO: The above is a hack to get the WebAgg backend
+ # working with `ipython --pylab` until proper integration
+ # is implemented.
@pelson Matplotlib Developers member
pelson added a note

Hmm. I'm sure you feel the same, but I'm not a fan of matplotlib knowing about ipython - I would sooner leave hooks so that ipython can make matplotlib know about it. Obviously, that isn't going to happen here, but is something that I will keep in the back of my mind as something we could improve in the future.

Other than that, I wonder what get_backend does and whether this plays nice with those brave souls who use the mpl OO interface (@dmcdougall I'm looking at you here :smile:)?

@mdboom Matplotlib Developers member
mdboom added a note

show shouldn't really come into play with the OO interface. This is really only relevant to the non-OO (matlab-style) interface.

I agree -- it would be nice to have matplotlib know less about IPython, but there's currently a very elaborate dance that the two projects do to make ipython --pylab work as well as it does. I think things are already better than they used to be, if you can believe it, in that IPython monkey-patches hooks in matplotlib in many cases, rather than matplotlib needing to have them already in place. But there's always more work to be done in that regard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bmu

It works, however the prompt is blocked by the server.

@bmu bmu commented on the diff
lib/matplotlib/backend_bases.py
@@ -41,6 +41,7 @@
#import matplotlib.path as path
from matplotlib import rcParams
from matplotlib import is_interactive
+from matplotlib import get_backend
@bmu
bmu added a note

Not sure, but I think this import is not necessary, as pyplot is imported in ShowBase.__call__ and you can use pyplot.get_backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mdboom
Matplotlib Developers member

Merging this and opening #1658 to propose non-blocking.

@mdboom mdboom merged commit e02c375 into matplotlib:master

1 check failed

Details default The Travis build failed
@mdboom mdboom deleted the mdboom:webagg/pylab_compatibility branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 10, 2013
  1. @mdboom

    A quick hack to get the WebAgg backend working with `ipython --pylab`…

    mdboom committed
    … until proper IPython integration can be done.
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +6 −1 lib/matplotlib/backend_bases.py
View
7 lib/matplotlib/backend_bases.py
@@ -41,6 +41,7 @@
#import matplotlib.path as path
from matplotlib import rcParams
from matplotlib import is_interactive
+from matplotlib import get_backend
@bmu
bmu added a note

Not sure, but I think this import is not necessary, as pyplot is imported in ShowBase.__call__ and you can use pyplot.get_backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
from matplotlib._pylab_helpers import Gcf
from matplotlib.transforms import Bbox, TransformedBbox, Affine2D
@@ -100,6 +101,10 @@ def __call__(self, block=None):
# IPython versions >= 0.10 tack the _needmain
# attribute onto pyplot.show, and always set
# it to False, when in --pylab mode.
+ ipython_pylab = ipython_pylab and get_backend() != 'WebAgg'
+ # TODO: The above is a hack to get the WebAgg backend
+ # working with `ipython --pylab` until proper integration
+ # is implemented.
@pelson Matplotlib Developers member
pelson added a note

Hmm. I'm sure you feel the same, but I'm not a fan of matplotlib knowing about ipython - I would sooner leave hooks so that ipython can make matplotlib know about it. Obviously, that isn't going to happen here, but is something that I will keep in the back of my mind as something we could improve in the future.

Other than that, I wonder what get_backend does and whether this plays nice with those brave souls who use the mpl OO interface (@dmcdougall I'm looking at you here :smile:)?

@mdboom Matplotlib Developers member
mdboom added a note

show shouldn't really come into play with the OO interface. This is really only relevant to the non-OO (matlab-style) interface.

I agree -- it would be nice to have matplotlib know less about IPython, but there's currently a very elaborate dance that the two projects do to make ipython --pylab work as well as it does. I think things are already better than they used to be, if you can believe it, in that IPython monkey-patches hooks in matplotlib in many cases, rather than matplotlib needing to have them already in place. But there's always more work to be done in that regard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
except AttributeError:
ipython_pylab = False
@@ -108,7 +113,7 @@ def __call__(self, block=None):
if ipython_pylab:
return
- if not is_interactive():
+ if not is_interactive() or get_backend() == 'WebAgg':
self.mainloop()
def mainloop(self):
Something went wrong with that request. Please try again.