Skip to content
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

Qt console --pylab=inline and getfigs(), etc. #638

Closed
dwf opened this issue Jul 29, 2011 · 13 comments
Closed

Qt console --pylab=inline and getfigs(), etc. #638

dwf opened this issue Jul 29, 2011 · 13 comments
Milestone

Comments

@dwf
Copy link
Contributor

dwf commented Jul 29, 2011

I was trying to modify some figures that I'd already created in --pylab=inline mode, and interestingly found that things behave somewhat weirdly, e.g. getfigs() doesn't work, and, for example, calling figure(1) repeatedly gets you a different object each time.

In [2]: figure(1)
Out[2]: <matplotlib.figure.Figure at 0x3c95e10>

In [3]: figure(1)
Out[3]: <matplotlib.figure.Figure at 0x3d213d0>

In [4]: figure(1)
Out[4]: <matplotlib.figure.Figure at 0x3d2ee10>

Should this be considered a bug?

@minrk
Copy link
Member

minrk commented Jul 29, 2011

Not a bug, since it's deliberate, if unpleasant. active figures get flushed at each output. This prevents all active figures being reprinted after every single input, but it also prevents there being any active figures between cells. You can still have Figure objects persist with references to them, they are just not 'active', having figure ID, responding to getfigs(), etc.

Marking as 'enhancement', since we would definitely like to improve this.

@dwf
Copy link
Contributor Author

dwf commented Jul 29, 2011

Yeah, I figured it was a side effect of the inline pylab magic. Well, good to document it on the issue tracker I guess.

@fperez
Copy link
Member

fperez commented Jul 30, 2011

I'll add a short note explaining this in the Qt console docs, but as indicated above it's not really a bug, just a consequence of how the system works in this case.

@fperez fperez closed this as completed Jul 30, 2011
@fperez
Copy link
Member

fperez commented Jul 30, 2011

Sorry @minrk, I didn't realize you wanted to keep it open. Do you actually foresee a way to improve the situation? If so, feel free to reopen. It's just that I'm not sure right now we can do a whole lot better...

@minrk
Copy link
Member

minrk commented Jul 30, 2011

I don't know much about matplotlib internals, but it doesn't seem like this should be difficult. All we want to do is have getfigs, etc. still reference existing figures, but not draw them every time. It does make it extremely unpleasant to interact with figures using the inline backend, so it should be kept open until we know it's too ugly/impossible to make it work.

@minrk minrk reopened this Jul 30, 2011
@fperez
Copy link
Member

fperez commented Jul 30, 2011

Well, there is a way to make that work, which is not to draw every time. But then it means that you need to call draw() or show() explicitly every time you actually want to see a plot. So a simple

plot(foo)

doesn't work anymore.

I've gotten used to this mode, but it would be easy to make it configurable (and even switchable at runtime) so that people can decide if they are OK with the explicit draw() requirement which gives them the stable references to figures, or if they prefer the current mode.

We can revisit this post release, so it does make sense to keep it open.

@dwf
Copy link
Contributor Author

dwf commented Jul 30, 2011

Thanks Fernando, I agree with Min that there is likely a clever solution that does what we want it to in "interactive" mode but also hangs onto active figures in roughly the same way a wx or Qt session would. I will give it some thought over the weekend.

minrk added a commit to minrk/ipython that referenced this issue Oct 18, 2011
This allows gcf(), getfigs(), etc. to be useful again in the qtconsole and notebook.

draw_if_interactive() signals that the current figure is to be drawn.

Figures that are created and closed in the same cell will not be drawn.

See ipython#638
@fperez
Copy link
Member

fperez commented Oct 19, 2011

@dwf. We're merging this one now; the default behavior won't change for now, but you can set the config value close_figures to False. You can drop this (@minrk, correct me if there's a more direct path to this one; you know the config arcana better than I):

c = get_config()
c.IPKernelApp.exec_lines = [
"from IPython.zmq.pylab import backend_inline",
"cfg = backend_inline.InlineBackendConfig.instance()",
"cfg.close_figures = False",
]

into a file named ipython_notebook_config.py in your ~/.ipython/profile_default directory, and that will do the trick.

After that change, you'll need to call figure() explicitly to get a new figure. See #892 for more details on the discussion.

You can put it in the default config if you want it applied everywhere instead of just in the notebook.

@fperez
Copy link
Member

fperez commented Oct 19, 2011

Closed by #892.

@fperez fperez closed this as completed Oct 19, 2011
@dwf
Copy link
Contributor Author

dwf commented Oct 19, 2011

This is great. Thanks for letting me know, I'll try it out!

@fperez
Copy link
Member

fperez commented Oct 19, 2011

BTW, it just hit me that exec_lines approach feels really silly now that our config files are pure python. It's an artifact of the old ipythonrc syntax, where I didn't want to try and parse multiline constructs, but now totally pointless.

I'll see if I can quickly hack up an exec_source and exec_function pair of flags that let you either paste a multiline block in a string or a function (the latter being the best option).

@fperez
Copy link
Member

fperez commented Oct 19, 2011

Scratch that, you can already do multilines, so it's just a matter of writing the above more cleanly:

c = get_config()

c.IPKernelApp.exec_lines = ["""
from IPython.zmq.pylab import backend_inline
cfg = backend_inline.InlineBackendConfig.instance()
cfg.close_figures = False
"""
                          ]

@fperez
Copy link
Member

fperez commented Oct 19, 2011

And just for the sake of completeness, as pointed out in #735, you can just do (even simpler):

c.InlineBackendConfig.close_figures = False

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
This allows gcf(), getfigs(), etc. to be useful again in the qtconsole and notebook.

draw_if_interactive() signals that the current figure is to be drawn.

Figures that are created and closed in the same cell will not be drawn.

See ipython#638
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