Skip to content
This repository

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

Closed
dwf opened this Issue July 29, 2011 · 13 comments

3 participants

David Warde-Farley Fernando Perez Min RK
David Warde-Farley
dwf commented July 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?

Min RK
Owner
minrk commented July 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.

David Warde-Farley
dwf commented July 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.

Fernando Perez
Owner
fperez commented July 29, 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.

Fernando Perez fperez closed this July 29, 2011
Fernando Perez
Owner
fperez commented July 29, 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...

Min RK
Owner
minrk commented July 29, 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.

Min RK minrk reopened this July 29, 2011
Fernando Perez
Owner
fperez commented July 29, 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.

David Warde-Farley
dwf commented July 29, 2011
Min RK minrk referenced this issue from a commit October 17, 2011
Commit has since been removed from the repository and is no longer available.
Min RK minrk referenced this issue from a commit in minrk/ipython October 17, 2011
Min RK don't close figures every cycle in inline backend
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 #638
6c22e3f
Fernando Perez
Owner

@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.

Fernando Perez fperez closed this October 18, 2011
Fernando Perez
Owner

Closed by #892.

David Warde-Farley
dwf commented October 18, 2011

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

Fernando Perez
Owner

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).

Fernando Perez
Owner

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
"""
                          ]
Fernando Perez
Owner

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

c.InlineBackendConfig.close_figures = False
Brian E. Granger ellisonbg referenced this issue from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.