| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Yes I was wondering if it should try and get the rendere from the current figure if there is one in pyplot. |
Sorry, something went wrong.
| get_axes = axes.fget | ||
|
|
||
| def _get_cachedRenderer(self, error_if_none=True): | ||
| # Get the cached renderer, raising an error if it doesn't exist yet |
There was a problem hiding this comment.
I guess if self._cachedRenderer is None, I'd do self.draw_without_rendering() here and force a renderer (I think).
Sorry, something went wrong.
There was a problem hiding this comment.
This is probably a behaviour change and outside the scope of this (bugfix) PR? Perhaps not though, I'm not very well acquainted with renderers etc.
Sorry, something went wrong.
There was a problem hiding this comment.
We already have a public method https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.get_renderer_cache.html ax.get_render_cache, do we want to prompt this to be public on the Figure too (or deprecate the one on Axes? We do not use it internally, it only shows up where it is defined, in an example, and in the source rst).
Sorry, something went wrong.
There was a problem hiding this comment.
Good question, and I'm not entirely sure what the answer is as I'm not too sure why/if a user would want to get the cached renderer.
Sorry, something went wrong.
There was a problem hiding this comment.
I think for exactly the reason we are getting it here!
I can see an argument than all of the renderer cache stuff should be private. It is a cache and there is no good reason for the user to be poking around the cache, we want to be able to replace/clear it/etc at will. On the other hand, we expose a couple of public functions that take a renderer as an "optional" (but only because fill it in with the cache) argument. Making renderers is a bit finicky (and if you make it your self no guarantee that it is consistent with anything you care about!).
Sorry, something went wrong.
There was a problem hiding this comment.
I guess this needs an API change note as the Error has changed in both cases?
Sorry, something went wrong.
| because that creates and caches the renderer needed here. | ||
| """ | ||
| if self._cachedRenderer is None: | ||
| raise AttributeError("draw_artist can only be used after an " |
There was a problem hiding this comment.
I suspect that this is raising AttributeError to maintain exact API compatibility with older versions of the code where _cachedRenderer was not an attribute until it was stashed 😱 .
Sorry, something went wrong.
|
I pushed this to 3.6 because I think this is a slightly bigger change than we want to put in a patch release, this is a very old bug, and there is multiple reasonable workarounds. |
Sorry, something went wrong.
|
I think this needs an API change note because the Exception type is changed. We may also want to do class NoRenderer(RuntimeError, AttributeError):
...and raise that instead (back-compatible and a more informative name). |
Sorry, something went wrong.
|
@dstansby popped this to draft until the rebase and API change note are done. I imagine it is mergeable at that point? |
Sorry, something went wrong.
|
I don't have time to pick this up in the short term - if someone else wants to feel free |
Sorry, something went wrong.
Sorry, something went wrong.
|
I think so.... |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
Adds Figure._get_cachedRenderer() which can be used to get the cached renderer, but error if it's not present. This can be used in one existing place, and is also now used in a legend method, which probably fixes #21285
PR Checklist