Skip to content

[MNT]: Interaction between savefig args transparent and facecolor/edgecolor make it impossible to spell out the signature of savefig #24413

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

Open
anntzer opened this issue Nov 9, 2022 · 0 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented Nov 9, 2022

Summary

In #24405 I tried to replace the current pyplot.savefig() wrapper manual implementation, which just has an unhelpful signature of *args, **kwargs, by a standard autogenerated pyplot wrapper, which copies the signature of Figure.savefig, which should itself match the signature of FigureCanvasBase.print_figure -- except for the fact that savefig adds a "transparent" kwarg not present in print_figure (and for a discrepancy in the name of the first argument: fname vs filename).

Unfortunately, the "transparent" kwarg has some problematic semantics (when set to True -- nothing happens when it is set to False): it always makes axes transparent, but the figure is made transparent only if the "facecolor" and "edgecolor" kwargs are unset -- if "facecolor"/"edgecolor" are None, then they are considered as set to the corresponding rcParams values (savefig.facecolor/savefig.edgecolor). This is actually documented behavior ("If True, the Axes patches will all be transparent; the Figure patch will also be transparent unless facecolor and/or edgecolor are specified via kwargs.")

This means that the real signature of print_figure is not print_figure(..., transparent=None [-> rcparam], facecolor=None [-> rcparam], edgecolor=None [-> rcparam], ...) but that facecolor/edgecolor can indeed not appear explicitly in the signature, only implicitly via **kwargs (or they have to instead default to some special placeholder like _UNSET). This is not a desirable state, e.g. due to the difficulty in providing introspection for the signature of savefig.

Proposed fix

Mildly break the API and instead make transparent=True override anything set by the facecolor and edgecolor kwargs, which should be rarely(?) used anyways.


See also #9080 (comment).

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

No branches or pull requests

1 participant