Skip to content

Add show() method to figure objects. #1615

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

Merged
merged 2 commits into from
Apr 18, 2012
Merged

Conversation

fperez
Copy link
Member

@fperez fperez commented Apr 17, 2012

This is a hack, but needed to match the monkeypatching applied by mpl in some backends (not all).

See #1612 and matplotlib/matplotlib#835 for more.

Closes #1612.

@fperez
Copy link
Member Author

fperez commented Apr 17, 2012

I should add that I have no way of unit-testing this, because it's simply up to checking that in various interactive use scenarios, the expected number of figures are displayed inline (it's easy to get spurious copies by mistake). Since that's a purely visual check, that's what I did.

As provided by @dwf, here's a snippet that runs fine in ipython --pylab but raises the AttributeError in ipython notebook --pylab=inline (or qtconsole):

import numpy as np
import matplotlib.pyplot as plt

plt.ioff()                                                                      
x = np.random.uniform(-5, 5, size=(100))
y = np.random.uniform(-5, 5, size=(100))
f = plt.figure()
plt.scatter(x, y)
plt.plot(y)
f.show()

ps - this could in principle be unittested, but it would be a really tricky test to write involving a 2-process check of objects being sent over the messaging channels. While it would be great to have machinery for such tests in the long run, that's a whole project by itself which I can't tackle right now.

@minrk
Copy link
Member

minrk commented Apr 17, 2012

@fperez - for things that cannot (or at least not easily) be unittested, @takluyver and I have been putting scripts in docs/examples/tests (actually, his is in examples/test_embed, which should probably be moved into docs/examples/tests), to at least ease reproduction.

@fperez
Copy link
Member Author

fperez commented Apr 17, 2012

Good idea, I'll do that now...

@dwf
Copy link
Contributor

dwf commented Apr 17, 2012

@fperez Yep, it seems to do the job for me. (I should note that in the case I was using it, the stuff I wanted to see was getting plotted, just after an annoying traceback.) Thanks!

@fperez
Copy link
Member Author

fperez commented Apr 17, 2012

thanks for the info, @dwf. Yes, it was getting shown because we still track that drawing happened and flush the drawing pipeline at the end of execution. But this is the right fix for this problem, thanks for confirming.

@fperez
Copy link
Member Author

fperez commented Apr 17, 2012

Ok, manual test pushed, thanks @minrk for the tip. I didn't want to do the cleanup of @takluyver's directory here, but I agree we should merge those manual tests into a single dir and put up a notice in the dev guide about it.

@ellisonbg
Copy link
Member

I think this looks good.

@fperez
Copy link
Member Author

fperez commented Apr 18, 2012

Great, thanks everyone for the review. Merging now.

fperez added a commit that referenced this pull request Apr 18, 2012
Add show() method to figure objects.

This is a hack, but needed to match the monkeypatching applied by matplotlib in some backends (not all).

See #1612 and matplotlib/matplotlib#835 for more details.

Closes #1612.
@fperez fperez merged commit 8df0574 into ipython:master Apr 18, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Add show() method to figure objects.

This is a hack, but needed to match the monkeypatching applied by matplotlib in some backends (not all).

See ipython#1612 and matplotlib/matplotlib#835 for more details.

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

Successfully merging this pull request may close these issues.

pylab=inline fig.show() non-existent in notebook
4 participants