-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[MNT]: FigureCanvasSVG has no attribute .get_renderer
#26007
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
Comments
.get_renderer
.get_renderer
The implementation is currently private at (See also #13099, though.) |
It's might help decide the right way forward to explain why one would need/want the renderer? Usually folks just switch to svg to print. |
My recollection is that the vector backends stream their output so outside of the save code it is not clear to me that we can even give the user a I would have to check the history, but I suspect |
Hey, thanks a lot for all the responses!! In general I agree with @tacaswell that this primarily makes sense for blitting (which is exactly where I ran into this) and in 99% of the use-cases this will concern Agg derived backends... Now, to answer the question of @jklymak on why one would need the renderer in the first place... To do this, I handle drawing artists myself which is currently implemented (very roughly) like this: import matplotlib.pyplot as plt
f, ax = plt.subplots()
ax.set_animated(True)
l, = ax.plot([0, 0.5, 1], [0, 0.5, 1], lw=20, animated=True)
def drawit(*args, **kwargs):
renderer = f.canvas.get_renderer()
l.set_color(plt.cm.prism(min(ax.get_xlim())))
l.draw(renderer)
for _, s in ax.spines.items():
s.draw(renderer)
f.canvas.mpl_connect("draw_event", drawit) This worked nicely for all my needs so far (including png, jpeg... export) but it fails on svg and pdf exports since there is no It might be that there is an entirely better way of implementing all of this (any insights are highly welcome!!) ... a general use-case concerning this issue would be:
|
When saving the matplotlib/lib/matplotlib/axes/_base.py Lines 3031 to 3034 in d464cbf
There is still the timing issue of when that will report true / false, when the |
@tacaswell Since for "svg/pdf" exports cached (agg-based) backgrounds are anyways irrelevant, a painless way to fix "svg/pdf" export would be to temporarily use If there is in fact no way to ensure a meaningful object is returned by |
But if you are in |
yes, but only for children of the axes in the |
Oh, that is a bug: matplotlib/lib/matplotlib/figure.py Lines 214 to 216 in d464cbf
That should be following the same rules as the filtering inside of |
ok... that's unfortunate... 😅 At the moment this was the most easy way I found to completely avoid the normal draw-cycle of an axes... is there a better way (preferably without subclassing Axes or Figure)? |
Summary
Hey,
while investigating possibilities for
svg
exports with EOmaps I realized that theFigureCanvasSVG
class does not expose the renderer via a.get_renderer()
method but initializes the renderer in.pring_svg()
.matplotlib/lib/matplotlib/backends/backend_svg.py
Lines 1330 to 1338 in 2f778fd
Is this intentional or is this a API inconsistency that should be fixed?
pdf
backendProposed fix
Implement
.get_renderer()
similar to theagg
backend:matplotlib/lib/matplotlib/backends/backend_agg.py
Lines 406 to 413 in 2f778fd
The text was updated successfully, but these errors were encountered: