Skip to content

Revert "Convert adjust_bbox to use ExitStack." #18089

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

Merged
merged 2 commits into from
Jul 29, 2020

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 28, 2020

PR Summary

With the ExitStack and context managers, it's expected that everything is called in pairs, i.e., adjust_bbox followed by restore_bbox. When saving, BackendBases.print_figure calls adjust_bbox before and restore_bbox after the renderer-specific method. In raster renderers, that's all that happens.

However, in mixed mode renderers, this is not the case. When it needs to rasterize (MixedModeRendering.start_rasterizing), it will change the DPI, restore the bbox, and re-adjust again. Internally, it hangs on to the new restore_bbox, but print_figure still has the original, which was cleared at the first start_rasterizing call, so when it calls restore_bbox, it does nothing because the stack is empty.

So all that means that we need to revert the original change, as it needs to be possible to call restore_bbox more than once. This has not been a direct revert, as other cleanups happened in the meantime.

Fixes #18061.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • [n/a] New features are documented, with examples if plot related
  • [n/a] Documentation is sphinx and numpydoc compliant
  • [n/a] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • [n/a] Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

With the `ExitStack` and context managers, it's expected that everything
is called in pairs, i.e., `adjust_bbox` followed by `restore_bbox`. When
saving, `BackendBases.print_figure` calls `adjust_bbox` before and
`restore_bbox` after the renderer-specific method. In raster renderers,
that's all that happens.

However, in mixed mode renderers, this is not the case. When it needs to
rasterize (`MixedModeRendering.start_rasterizing`), it will change the
DPI, restore the bbox, and re-adjust again. Internally, it hangs on to
the new `restore_bbox`, but `print_figure` still has the original, which
was cleared at the first `start_rasterizing` call, so when it calls
`restore_bbox`, it does nothing because the stack is empty.

So all that means that we need to revert the original change, as it
needs to be possible to call `restore_bbox` more than once. This has not
been a direct revert, as other cleanups happened in the meantime.
@QuLogic QuLogic added this to the v3.3.1 milestone Jul 28, 2020
@QuLogic
Copy link
Member Author

QuLogic commented Jul 28, 2020

BTW, no tests failed when this change was made, but the example from the issue is a bit long. I will try and figure out a simpler example so this is properly tested.

@jklymak jklymak merged commit fcecbed into matplotlib:master Jul 29, 2020
@lumberbot-app
Copy link

lumberbot-app bot commented Jul 29, 2020

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.3.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 fcecbedf502afbf17e04878490d014cdaf725254
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #18089: Revert "Convert adjust_bbox to use ExitStack."'
  1. Push to a named branch :
git push YOURFORK v3.3.x:auto-backport-of-pr-18089-on-v3.3.x
  1. Create a PR against branch v3.3.x, I would have named this PR:

"Backport PR #18089 on branch v3.3.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.3.0 regression in png backend with colorbar()
3 participants