Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@anntzer

Description

@anntzer
Issue body actions

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).

story645 and ZPyrolink

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.