-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Matplotlib blitting in Jupyter Notebooks (issue #4288) #9240
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
Conversation
Hi, I'm unsure as well how to do a scripted notebook test as well. However, to start you could post your test code that can be pasted into a reviewers notebook. |
@mbewley Thanks for taking this on! If you have any questions (code or process) please do not hesitate to ask! You will probably get faster answers asking publically (here or on https://gitter.im/matplotlib/matplotlib ) but if there is anything you do not feel comfortable asking publicly email me. |
Here's the minimal example that works inside a notebook... just click on the generated 49 MP image, and it will rapidly toggle a little red/green box in the top left.
|
Looks like a sensible change (untested). To be clear, the blitting you are adding is on the server side - you aren't getting any blitting through the javascript and into the notebook. That's fine (and a hard problem to solve), but we should be careful not to call it full-blown blitting in the nbagg backend.
Wow! Really impressive stuff - there is a lot of connective tissue you've had to get your head around, and you've done a great job of it as far as I can see! Keep up the awesome work - looking forward to seeing your future mpl contributions 👍 |
Ha, the "connective tissue" was all blink1073 - I just managed to copy/paste correctly (and do a neat minimal example). Yes, the server side blitting works perfectly on local host for fast access. It also works quite quickly on EC2 (tested at work where we have a pretty fast connection), but chews up monstrous amounts of bandwidth - so maybe should come with some sort of warning? |
Hey guys, is there anything we need to do to make sure this gets into 2.2? (it was slated for 2.1, but got bumped). |
I labelled it release critical so that we're sure to take a look at it before the next feature release. |
Thanks! |
power cycled to re-trigger CI. |
Or put your example in the UAT notebook. |
Hmm, I didn't see those issues. I've now:
Anything else I need to do? |
Hey, any feedback on the updates? |
Can you update the UAT notebook as part of this PR? Any theories on the flickering? |
What did you want updated on the UAT notebook? I added it into the repo and checked it ran - the tests all still seemed sensible. |
@mbewley just for the changes to be check-in as part of this PR so that the next person to work on this can run them. |
Ah, sorry, thought I'd done that - forgot to push. Will do... |
oops, looks like you accidentally rebased in a bunch of other commits... |
Hmm, I was trying to update to the latest head on master, as it was getting pretty old. What's the best way to fix it? |
To rebase, I always squash my own commits
Then I rebase with master:
See: When I've gotten in the state that you are in, I copy the files I edited somewhere else and then in my branch:
and then re-add the changes. |
Ok, I thought I followed this: https://matplotlib.org/devel/gitwash/development_workflow.html#development-workflow ("Rebasing on Trunk"), but must've stuffed it up. Will fix and push again. |
… compatibility with latest jupyter notebook).
@@ -215,6 +223,11 @@ def get_diff_image(self): | |||
# Swap the renderer frames | |||
self._renderer, self._last_renderer = ( | |||
self._last_renderer, renderer) | |||
|
|||
self.figure._cachedRenderer = self._renderer | |||
for ax in self.figure.axes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't cache the renderer on the axes anymore, so these two lines should go away
ping @mbewley - sometimes takes a while to get things through matplotlib - hopefully the process hasn't scared you off! |
This still does not deal with the double-buffering correctly. For example in %matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')
def init():
ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1, 1)
return ln,
def update(frame):
xdata.append(frame)
ydata.append(np.sin(frame))
ln.set_data(xdata, ydata)
return ln,
ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
init_func=init, blit=True)
plt.show() every other frame has the incorrect tick labels. I think instead of using two |
Replaced the second Agg renderer by storing the previous buffer in a private attribute. Removing the second renderer eliminates the the flickering issues noted in: matplotlib#9240 (comment) Also, did not need to implement copy_from_bbox as that is inherited from backend_agg.FigureCanvasAgg
Replaced the second Agg renderer by storing the previous buffer in a private attribute. Removing the second renderer eliminates the the flickering issues noted in: matplotlib#9240 (comment) Also, did not need to implement copy_from_bbox as that is inherited from backend_agg.FigureCanvasAgg
…g figure taking the example from matplotlib#9240 Co-Authored-By: Thomas A Caswell <tcaswell@gmail.com>
…g figure taking the example from matplotlib#9240 Co-Authored-By: Thomas A Caswell <tcaswell@gmail.com>
…g figure taking the example from matplotlib#9240 Co-Authored-By: Thomas A Caswell <tcaswell@gmail.com>
I'll closed as abandoned; thanks for the PR, and feel free to re-open if you want to come back to this! |
For any future finders of this PR: This was subsumed and then superceded by #19059 |
PR Summary
Blitting is not currently supported by matplotlib when used in Jupyter notebooks (with the magic %matplotlib notebook).
@blink1073 wrote some code to make it work some time back, but didn't merge it in. I've taken his changes (he said he wasn't interested in doing it himself), and applied them to the latest version of matplotlib.
This is discussed in issue #4288. I was asked to do the pull request - first time contributor to matplotlib. I've tested it with a minimal example Jupyter notebook, but am unsure how to test whether blitting works in notebooks in scripted unit tests.