Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
_blit_draw function fix to correctly show the moving axis#21801
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping@matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join uson gitter for real-time discussion.
For details on testing, writing docs, and our review process, please seethe developer guide
We strive to be a welcoming and open project. Please follow ourCode of Conduct.
This could well be correct, but how did you test it? In particular, did you test the performance aspects? Thanks! |
I tried with a simple plot and plots made with subplot2grid. Showing the animation in real time or saving the video. With subplot2grid I tried configurations with figures using rowspan and figures using colspan. The colspan figures share the x axis, which is also moved by the animation. Both simple and subplot2grid works well, with a general result similar to the current matplotlib code. The only different is "old" code is not showing labels in the axis in move while the "new" code show labels and update the label correctly. The "old" code also have problems if the window is moved while the animation is on. While normally there is no labels, the labels for the animation frame in use are printed when you drop the window with the mouse. These labels not dissapear with the next frame. If you move the window several times the axis start looking horrible, with different labels on top of each other. With this PR is not happening, the labels still changing and updating not matter if you move the window. If necessary I can make a little video to show the problem, in the case you don't understand what I am triying to say. About the performance as far I can test seems the same as the "old" code. Running directly on python with my data is running ok but maybe not flawless, but I think is normal. Saving the video the result run perfectly fine. For both cases the result is the same with or without the PR. Also the production time for the video is the same with or without the PR. I am using Debian. The majority of the test were using my production environment with Anaconda and Python 3.7 or 3.9 and thus matplotlib 3.4. What I tried with matplotlib current main branch looks fine too but i didn't make to many test compared to 3.4. |
# Make a separate pass to draw foreground. | ||
for a in artists: | ||
a.axes.draw_artist(a) | ||
# After rendering all the needed artists, blit each axes individually. | ||
for ax in updated_ax: | ||
ax.figure.canvas.blit(ax.bbox) | ||
ax.figure.canvas.blit(ax.figure.bbox) |
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.
This well effectively blit the whole figure number-of-axess times.
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.
Yes, I have been test it and I think with one call is enough. Maybe the solution is remove that final for and just get directly the figure.bbox and call blit just one time.
This code path does not affect saving (we, for better or worse) always fully render each frame when saving. One thing to keep in mind is that text is frequently the most expensive thing to draw so if you are changing the ticks etc, the benefit of blitting may be minimal (which is obviously a generalization and breaking rule 0 of performance tuning which is benchmark first, then talk). While this works, it is adding a bunch of duplicate work. I think the right fix here is either to sort out how to extend the boinding box grabbed for the Axes to include the decorations or to remove all of the per-axes logic and just do it at the figure level (PS sorry for the long delay between the line comment and this comment...things came up and this sat un-sent for the last 6 hours!) |
Part of the extensive logic in there is trying to figure out the right time to save the background for blitting and making sure things are "clean". I wonder if that's not quite hitting the right time. |
jklymak commentedDec 16, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've popped this to draft until the architecture can be sorted out. I'm not understanding how blitting the whole figure is any different from redrawing the whole figure, in which case you may as well not blit. I thought the point of blitting was to avoid the costly axes spine and label redraw steps, and just change the artists inside the axes, which are usually cheaper. If you are changing the spines and labels, then obviously you can't save those expensive steps. I would assume that for cases where you only change the interior of the axes, this PR has made thingsfar slower. So this would need performance proof, with reproducible examples that are shared that a) it works for the new examples and b) that it does not slow down pure blitting examples. |
Getting the image on the screen is a two(+) step process:
Where the speed in blitting comes from is that we can cache a big fraction of the work (this is the I've pushed this to future releases because re-reading this I still think that while expanding the space of what gets re-drawn to possibly include the tick labels is useful, it needs to be done more surgically / in a opt-in way or the whole management scheme needs to be updated. |
@ManuRS are you still interested in working on this? |
PR Summary
Function _blit_draw in animation.py is not showing and not updating the labels of the axis in move.
The bbox accessed directly as "ax.bbox" is not working. Using "ax.figure.bbox" solved the problem and the axes are plotted and updating correctly.
Is the first time I am contributing to this kind of project, sorry if something is incorrect. As far I can test this is working for me. I have been using this fix as a workaround for my personal use since 1.17. Even _blit_draw have been reworked and the same change still have a consistent behaviour fixing the problem.
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).