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
Comments
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. |
Yeah, I figured it was a side effect of the inline pylab magic. Well, good to document it on the issue tracker I guess. |
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. |
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... |
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. |
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. |
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. |
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
@dwf. We're merging this one now; the default behavior won't change for now, but you can set the config value 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 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. |
Closed by #892. |
This is great. Thanks for letting me know, I'll try it out! |
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). |
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 """ ] |
And just for the sake of completeness, as pointed out in #735, you can just do (even simpler): c.InlineBackendConfig.close_figures = False |
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
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.
Should this be considered a bug?
The text was updated successfully, but these errors were encountered: