-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Don't set savefig.facecolor/edgecolor in dark_background/538 styles. #28156
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
Conversation
Why do we have savefig.facecolor at all? Wouldn’t it be reasonable to always save the figure as is? If a user wants a different background, they can configure the figure background directly. |
This is a hold over from the 1.x days when the figure face color was gray and we had a second face color (which defaulted to |
@@ -0,0 +1,12 @@ | |||
dark_background and fivethirtyeight styles no longer set ``savefig.facecolor`` and ``savefig.edgecolor`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This filename is not updated with the PR number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, fixed
Previously, the dark_background and fivethirtyeight styles would set the savefig.facecolor and savefig.edgecolor rcParams to the same values as figure.facecolor and figure.edgecolor; i.e., if a user uses a style but tweaks the figure facecolor, this tweak is lost (overridden) when saving the figure. A concrete example would be using the dark_background style but wanting a dark gray background instead of a black one, e.g. `mpl.style.use(["dark_background", {"figure.facecolor": ".2"}]); plot(); savefig(...)`. In all likelihood these values were set because the styles predate the ability to set these savefig rcParams to "auto", which means "don't change the figure facecolor, just use it as is" (a feature introduced exactly because this auto-switching of color by savefig was confusing users). Now we can just remove these rcParams from the two styles (which are the only ones affected by the issue -- the grayscale style also sets savefig.facecolor but to a value different from figure.facecolor) and let them inherit the global default value, "auto".
The appevyor failure looks sphinx related. |
I don't think there is any bug to report, but I just want to note one thing that confused me for a while when going from 3.9 to 3.10 with this change in case it helps someone else. For code like: pyplot.gcf()
pyplot.style.use("dark_background")
<generate plot...>
pyplot.savefig("fig.png") With 3.9, this code will produce a figure with a black border. With 3.10, it will produce a figure with a white border because the |
Previously, the dark_background and fivethirtyeight styles would set the savefig.facecolor and savefig.edgecolor rcParams to the same values as figure.facecolor and figure.edgecolor; i.e., if a user uses a style but tweaks the figure facecolor, this tweak is lost (overridden) when saving the figure. A concrete example would be using the dark_background style but wanting a dark gray background instead of a black one, e.g.
mpl.style.use(["dark_background", {"figure.facecolor": ".2"}]); plot(); savefig(...)
.In all likelihood these values were set because the styles predate the ability to set these savefig rcParams to "auto", which means "don't change the figure facecolor, just use it as is" (a feature introduced in #15111 exactly because this auto-switching of color by savefig was confusing users). Now we can just remove these rcParams from the two styles (which are the only ones affected by the issue -- the grayscale style also sets savefig.facecolor but to a value different from figure.facecolor) and let them inherit the global default value, "auto".
PR summary
PR checklist