Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handle rasterization start & stop only from Artist #24293

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

Closed
wants to merge 1 commit into from

Conversation

xerus
Copy link
Contributor

@xerus xerus commented Oct 28, 2022

PR Summary

As mentionedd in 3.4.0 api changes behaviour.rst the tracking should be handled there.

This commit avoids calling stop_rasterizing method twice in row making it throw an exception.

Fixes #24235

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

As mentionedd in 3.4.0 api changes behaviour.rst the tracking should
be handled there.

This commit avoids calling stop_rasterizing method twice in row making
it throw an exception.

Fixes matplotlib#24235
Copy link

@github-actions github-actions bot 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 us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@oscargus
Copy link
Member

Thanks! Can you please add a test that fails in current main, but passes with this? (Probably similar to the example in #24235 but possibly shorter.)

Not sure if this only happens for PDF files, but if that is the best way you can probably write to a buffer rather than stating a file name and make clear that it is a smoke test with a comment like # smoke test for GH#24235.

@tacaswell tacaswell added this to the v3.6.3 milestone Oct 28, 2022
@tacaswell
Copy link
Member

This is not the correct fix as it eliminates the functionality of resterizing all artists below a given zorder.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this does fix the reported issue, it eliminates another functionality.

@tacaswell
Copy link
Member

The correct fix is to pull the depth counting logic from

def allow_rasterization(draw):
"""
Decorator for Artist.draw method. Provides routines
that run before and after the draw call. The before and after functions
are useful for changing artist-dependent renderer attributes or making
other setup function calls, such as starting and flushing a mixed-mode
renderer.
"""
@wraps(draw)
def draw_wrapper(artist, renderer):
try:
if artist.get_rasterized():
if renderer._raster_depth == 0 and not renderer._rasterizing:
renderer.start_rasterizing()
renderer._rasterizing = True
renderer._raster_depth += 1
else:
if renderer._raster_depth == 0 and renderer._rasterizing:
# Only stop when we are not in a rasterized parent
# and something has be rasterized since last stop
renderer.stop_rasterizing()
renderer._rasterizing = False
if artist.get_agg_filter() is not None:
renderer.start_filter()
return draw(artist, renderer)
finally:
if artist.get_agg_filter() is not None:
renderer.stop_filter(artist.get_agg_filter())
if artist.get_rasterized():
renderer._raster_depth -= 1
if (renderer._rasterizing and artist.figure and
artist.figure.suppressComposite):
# restart rasterizing to prevent merging
renderer.stop_rasterizing()
renderer.start_rasterizing()
draw_wrapper._supports_rasterization = True
return draw_wrapper
and re-implement it here. I do not think we can directly use that wrapper as it does some extra stuff with the arists and agg_filter that we do not want here and a refactoring of the depth counting code that would compose the correct way with the other logic an that wrapper is not worth the complexity for avoiding 2 copies of like 10 lines of code.

Probably should also move the start_rasterizing and stop_rasterizing closer together so we can put the later in a finally.

@QuLogic
Copy link
Member

QuLogic commented Dec 22, 2022

I believe this has been replaced by #24768.

@QuLogic QuLogic closed this Dec 22, 2022
@QuLogic QuLogic modified the milestones: v3.6.3, v3.7.0 Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: pcolormesh(rasterized=True) conflicts with set_rasterization_zorder()
4 participants