Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

_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

Draft
ManuRS wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromManuRS:animation_blit_draw-fix

Conversation

ManuRS
Copy link

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

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

Copy link

@github-actionsgithub-actionsbot left a 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.

@jklymak
Copy link
Member

This could well be correct, but how did you test it? In particular, did you test the performance aspects? Thanks!

@ManuRS
Copy link
Author

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)
Copy link
Member

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.

Copy link
Author

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.

@tacaswell
Copy link
Member

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

@tacaswelltacaswell added this to thev3.6.0 milestoneDec 3, 2021
@dopplershift
Copy link
Contributor

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.

@jklymakjklymak marked this pull request as draftDecember 16, 2021 09:51
@jklymak
Copy link
Member

jklymak commentedDec 16, 2021
edited
Loading

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.

@QuLogicQuLogic modified the milestones:v3.6.0,v3.7.0Jul 5, 2022
@tacaswell
Copy link
Member

Getting the image on the screen is a two(+) step process:

  1. we render a raster image
  2. we copy the raster into the surface of a GUI widget
  3. the GUI framework does what ever it does to eventually light up the pixels on your screen

Where the speed in blitting comes from is that we can cache a big fraction of the work (this is thecopy_from_bbox part) that has everything that doesnot change between frames so we can then only pay the cost in (1) for re-drawing what has changed.

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.

@tacaswell
Copy link
Member

@ManuRS are you still interested in working on this?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
Status: Waiting for author
Milestone
future releases
Development

Successfully merging this pull request may close these issues.

5 participants
@ManuRS@jklymak@tacaswell@dopplershift@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp