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
"%matplotlib notebook" required before *every* call to plot? #4879
Comments
At the moment the interactive figure in the nbagg backend is designed to work like a regular interactive GUI figure (QT,GTK etc) so each call to plot will plot in the latest active figure if a figure exists or otherwise create a new one. Therefore you end up with two two identical lines on top of each other in your first example. I'm not sure if this is the right solution since you are effectively plotting in the output of another cell which may be confusing. There is an issue with when the figure is closed i.e. #4841 which may be related. At the moment the solution is to explicitly create a new figure when you want one. plt.figure()
plt.plot([1,2,3])
... Personally I tend to prefer the OO interface. fig, ax = plt.subplots(1,1)
ax.plot()
ax.set_xlabel('foo')
... While somewhat more verbose it makes the intend more obvious. |
@jenshnielsen Aha! I hadn't tried |
Another way to look at it is that the inline backend effectively closes the We have had "bug reports" going both ways now. In an early iteration of the On Fri, Aug 7, 2015 at 6:03 AM, Ian Ozsvald notifications@github.com
|
@WeatherGod I've not found any official docs on |
I would like to reiterate a need for further information about the notebook interactive backend. |
This should be an option. Maybe specify %matplotlib notebook vs %matplotlib notebook-overwrite ? |
Note that there is one other notebook-specific way to display plots now - the ipympl widget. |
Thx. I made a module that thinly wraps MPL's plotting functions; uses syntax like plt.plot(...), but does it with fig/ax objects so it works with notebook; I just import it instead of pyplot when using notebooks. Feels hacky, but haven't found a better option. |
If you have a long notebook with multiple plots, you certainly don't want to be scrolling all the way back up to the first cell to see your output ... Personally I much prefer the %matplotlib inline behaviour, although the actual plots in %matplotlib notebook look a lot nicer.
|
We have a strong preference for the object-oriented API. So each new figure starts with either plt.figure or plt.subplots. I don’t think there is much appetite for changing this so that plt.plot makes a new figure. Indeed there are perfectly valid reasons to want a new cell to operate on an old figure and the current paradigm allows that. |
Personally, I would still like to see at least an option where, as with %matplotlib inline, the "backend effectively closes the figure object after executing each cell" (as Weathergod commented above). I use notebooks primarily for teaching, and students find this behaviour more natural/intuitive. |
Hi all, although this discussion is closed, I would like to share a video by professor Christopher Brooks getting into some details why to use "%matplotlib notebook," as well as a paper on what's behind matplotlib in general (going through the different layers): Video: https://www.coursera.org/lecture/python-plotting/matplotlib-architecture-bQ4Ld |
@kaloatanasov I watched the video, but I didn't speak the reason why to use "%matplotlib notebook". He simply said that he will use `"%matplotlib inline" for his class. Where can I exactly find the reason? |
The behaviour of "%matplotlib notebook" is different to "%matplotlib inline", I've attached a screenshot, can you help me figure out if this is my machine or if I'm doing something silly? I am expecting both magics to produces similar behaviour. I've seen this issue over the last few months in bigger Notebooks and I figured I had other problems but now I've narrowed it down to just the simple case outlined below.
The problem:
%matplotlib inline
in a Notebook causes plots to be shown as static images, only 1 call to%matplotlib inline
is required.%matplotlib notebook
in a Notebook enables some interactive features. I have to call this before every plot otherwise I get a non-rendered object in return.Here I only use
%matplotlib notebook
. The second plot is not rendered. For the third plot I force another call to%matplotlib notebook
and the third image is rendered.Here I first use
%matplotlib inline
and then%matplotlib notebook
. The final plot (second fornotebook
) doesn't render:I'm using:
Maybe I'm being foolish and the point of
%matplotlib notebook
is to only allow 1 plot to be interactive, so you have to choose which one? And then after switch back to%matplotlib inline
?Any thoughts to clear up my muddled mind would be gladly received. i.
The text was updated successfully, but these errors were encountered: