Skip to content

Make sure SubFigure has _cachedRenderer#23174

Merged
tacaswell merged 1 commit into
matplotlib:mainfrom
oscargus:clabelsubfigures
Jun 2, 2022
Merged

Make sure SubFigure has _cachedRenderer#23174
tacaswell merged 1 commit into
matplotlib:mainfrom
oscargus:clabelsubfigures

Conversation

@oscargus

@oscargus oscargus commented Jun 1, 2022

Copy link
Copy Markdown
Member

PR Summary

Makes sure that _cachedRenderer is added to SubFigure instances by moving it to FigureBase. Closes #23173

Maybe the code in contour should behave differently, but I assume that sooner or later the same problem may happen in other code when applied to a SubFigure and not a Figure.

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] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus oscargus changed the title Make sure SubFigure have _cachedRenderer Make sure SubFigure has _cachedRenderer Jun 1, 2022
@jklymak

jklymak commented Jun 1, 2022

Copy link
Copy Markdown
Member

I'm not sure this is the correct fix? The renderer for the subfigure should be the same as the parent's renderer. I think we need to set this up as a property and have the getter go up the tree to the parent?

@oscargus

oscargus commented Jun 1, 2022

Copy link
Copy Markdown
Member Author

I'm not sure this is the correct fix?

No idea. What you says make sense though, so I'll give it a go.

@oscargus

oscargus commented Jun 1, 2022

Copy link
Copy Markdown
Member Author

On draw SubFigure redefines the _cachedRenderer. Will there ever be cases where it differs from the parent renderer?

@oscargus oscargus force-pushed the clabelsubfigures branch from 02fde42 to ad1dfe5 Compare June 1, 2022 11:24
@oscargus oscargus force-pushed the clabelsubfigures branch from ad1dfe5 to 4e5019e Compare June 1, 2022 11:32
@oscargus

oscargus commented Jun 1, 2022

Copy link
Copy Markdown
Member Author

Updated with properties. Not convinced that one need to set the renderer in draw, but guess it shouldn't hurt?

@jklymak

jklymak commented Jun 1, 2022

Copy link
Copy Markdown
Member

The subfigure really should not have a cached renderer, but subfigures have been abstracted to be like figures so that child artists don't know if they are in a figure or a subfigure. So if an artist does self.figure._cachedRenderer that should always point to the top-most renderer.

@jklymak

jklymak commented Jun 1, 2022

Copy link
Copy Markdown
Member

I think this is correct. Note that #22745 would have fixed this as well by calling figure._get_renderer().

@oscargus

oscargus commented Jun 1, 2022

Copy link
Copy Markdown
Member Author

Note that #22745 would have fixed this as well by calling figure._get_renderer().

Ahh, OK! Maybe better to try to get that in then? I have not really followed (nor fully understand) that discussion.

I guess that the test added here very well can be worthwhile keeping as it seems to exercise the code in a way that once was (currently is) broken.

@jklymak

jklymak commented Jun 1, 2022

Copy link
Copy Markdown
Member

I think we can have both fixes. #22745 isn't necessarily going to go in ;-)

@tacaswell tacaswell added this to the v3.5.3 milestone Jun 1, 2022
@tacaswell

Copy link
Copy Markdown
Member

I suspect this is an argument as to why we actually do need to cache the renderer (and should move it to a central canonical place) and my position that we should not cache it at all is wrong (or at least currently infeasible).

@tacaswell tacaswell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Anyone can merge on green.

@tacaswell

Copy link
Copy Markdown
Member

I restarted the failed windows job (it was a blit test in a subprocess I have not seen fail before 🤞🏻 it is transient).

@tacaswell tacaswell merged commit af83578 into matplotlib:main Jun 2, 2022
@lumberbot-app

lumberbot-app Bot commented Jun 2, 2022

Copy link
Copy Markdown

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.5.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 af835787ac405d6021d4ed11e57734873c401b9c
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #23174: Make sure SubFigure has _cachedRenderer'
  1. Push to a named branch:
git push YOURFORK v3.5.x:auto-backport-of-pr-23174-on-v3.5.x
  1. Create a PR against branch v3.5.x, I would have named this PR:

"Backport PR #23174 on branch v3.5.x (Make sure SubFigure has _cachedRenderer)"

And apply the correct labels and milestones.

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

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

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

tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Jun 2, 2022
Merge pull request matplotlib#23174 from oscargus/clabelsubfigures

FIX: Make sure SubFigure has _cachedRenderer
(cherry picked from commit af83578)
timhoffm added a commit that referenced this pull request Jun 4, 2022
…-v3.5.x

Backport PR #23174: Make sure SubFigure has _cachedRenderer
imgbot Bot pushed a commit to kkipngenokoech/matplotlib that referenced this pull request Apr 19, 2026
Merge pull request matplotlib#23174 from oscargus/clabelsubfigures

FIX: Make sure SubFigure has _cachedRenderer
(cherry picked from commit af83578)
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]: Crash when adding clabels to subfigures

3 participants