From 3d758e2dfdda315828b1359361bc083a9fffab01 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 30 Apr 2024 18:06:43 +0200 Subject: [PATCH] Don't set savefig.facecolor/edgecolor in dark_background/538 styles. 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". --- doc/api/next_api_changes/behavior/28156-AL.rst | 12 ++++++++++++ .../mpl-data/stylelib/dark_background.mplstyle | 3 --- .../mpl-data/stylelib/fivethirtyeight.mplstyle | 5 +---- 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 doc/api/next_api_changes/behavior/28156-AL.rst diff --git a/doc/api/next_api_changes/behavior/28156-AL.rst b/doc/api/next_api_changes/behavior/28156-AL.rst new file mode 100644 index 000000000000..af9c2b142261 --- /dev/null +++ b/doc/api/next_api_changes/behavior/28156-AL.rst @@ -0,0 +1,12 @@ +dark_background and fivethirtyeight styles no longer set ``savefig.facecolor`` and ``savefig.edgecolor`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When using these styles, :rc:`savefig.facecolor` and :rc:`savefig.edgecolor` +now inherit the global default value of "auto", which means that the actual +figure colors will be used. Previously, these rcParams were set to the same +values as :rc:`figure.facecolor` and :rc:`figure.edgecolor`, i.e. a saved +figure would always use the theme colors even if the user manually overrode +them; this is no longer the case. + +This change should have no impact for users that do not manually set the figure +face and edge colors. diff --git a/lib/matplotlib/mpl-data/stylelib/dark_background.mplstyle b/lib/matplotlib/mpl-data/stylelib/dark_background.mplstyle index c4b7741ae440..61a99f3c0d10 100644 --- a/lib/matplotlib/mpl-data/stylelib/dark_background.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/dark_background.mplstyle @@ -18,9 +18,6 @@ grid.color: white figure.facecolor: black figure.edgecolor: black -savefig.facecolor: black -savefig.edgecolor: black - ### Boxplots boxplot.boxprops.color: white boxplot.capprops.color: white diff --git a/lib/matplotlib/mpl-data/stylelib/fivethirtyeight.mplstyle b/lib/matplotlib/mpl-data/stylelib/fivethirtyeight.mplstyle index 738db39f5f80..cd56d404c3b5 100644 --- a/lib/matplotlib/mpl-data/stylelib/fivethirtyeight.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/fivethirtyeight.mplstyle @@ -29,10 +29,7 @@ xtick.minor.size: 0 ytick.major.size: 0 ytick.minor.size: 0 -font.size:14.0 - -savefig.edgecolor: f0f0f0 -savefig.facecolor: f0f0f0 +font.size: 14.0 figure.subplot.left: 0.08 figure.subplot.right: 0.95