From 058f1d191cfe5b7c36977451b1a7cd8255487e75 Mon Sep 17 00:00:00 2001 From: Rob Righter Date: Sat, 18 Feb 2023 21:29:50 -0500 Subject: [PATCH 1/2] RR - Set default facecolor for subfigures to be none (Transparent). Fixes issue #24910 --- .../next_api_changes/behavior/25255-RR.rst | 5 +++++ lib/matplotlib/figure.py | 6 +++--- lib/matplotlib/tests/test_figure.py | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 doc/api/next_api_changes/behavior/25255-RR.rst diff --git a/doc/api/next_api_changes/behavior/25255-RR.rst b/doc/api/next_api_changes/behavior/25255-RR.rst new file mode 100644 index 000000000000..1eb51f454cc5 --- /dev/null +++ b/doc/api/next_api_changes/behavior/25255-RR.rst @@ -0,0 +1,5 @@ +``SubFigure`` default facecolor is now transparent +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Subfigures default facecolor changed to ``"none"``. Previously the default was +the value of ``figure.facecolor``. diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index a7873d54a0a4..f10ea0a7df96 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2155,8 +2155,8 @@ def __init__(self, parent, subplotspec, *, Defines the region in a parent gridspec where the subfigure will be placed. - facecolor : default: :rc:`figure.facecolor` - The figure patch face color. + facecolor : default: ``"none"`` + Transparent face color. edgecolor : default: :rc:`figure.edgecolor` The figure patch edge color. @@ -2176,7 +2176,7 @@ def __init__(self, parent, subplotspec, *, """ super().__init__(**kwargs) if facecolor is None: - facecolor = mpl.rcParams['figure.facecolor'] + facecolor = "none" if edgecolor is None: edgecolor = mpl.rcParams['figure.edgecolor'] if frameon is None: diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 8ee6bf2d2751..e29397f3c2ec 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -287,6 +287,25 @@ def test_suptitle_fontproperties(): assert txt.get_weight() == fps.get_weight() +<<<<<<< HEAD +@image_comparison(['figure_suptitle_subfigures'], + extensions=['png']) +======= +>>>>>>> bb69a2fbc5 (RR - convert visual test to simple unit test.) +def test_suptitle_subfigures(): + fig = plt.figure(figsize=(4, 3)) + sf1, sf2 = fig.subfigures(1, 2) + sf2.set_facecolor('white') + sf1.subplots() + sf2.subplots() + fig.suptitle("This is a visible suptitle.") + + # verify the first subfigure facecolor is the default transparent + assert sf1.get_facecolor() == (0.0, 0.0, 0.0, 0.0) + # verify the second subfigure facecolor is white + assert sf2.get_facecolor() == (1.0, 1.0, 1.0, 1.0) + + @image_comparison(['alpha_background'], # only test png and svg. The PDF output appears correct, # but Ghostscript does not preserve the background color. @@ -1211,12 +1230,14 @@ def test_subfigure(): pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2, vmax=2) sub[0].colorbar(pc, ax=axs) sub[0].suptitle('Left Side') + sub[0].set_facecolor('white') axs = sub[1].subplots(1, 3) for ax in axs.flat: pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2, vmax=2) sub[1].colorbar(pc, ax=axs, location='bottom') sub[1].suptitle('Right Side') + sub[1].set_facecolor('white') fig.suptitle('Figure suptitle', fontsize='xx-large') From 9d827a8f2b0ca9fd7c172e6a6950f934ad8a53c5 Mon Sep 17 00:00:00 2001 From: Rob Righter Date: Mon, 20 Feb 2023 20:54:14 -0500 Subject: [PATCH 2/2] RR - Resolve merge conflict --- lib/matplotlib/figure.py | 2 +- lib/matplotlib/tests/test_figure.py | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index f10ea0a7df96..94b86651e749 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2156,7 +2156,7 @@ def __init__(self, parent, subplotspec, *, be placed. facecolor : default: ``"none"`` - Transparent face color. + The figure patch face color; transparent by default. edgecolor : default: :rc:`figure.edgecolor` The figure patch edge color. diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index e29397f3c2ec..80d80f969163 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -287,11 +287,6 @@ def test_suptitle_fontproperties(): assert txt.get_weight() == fps.get_weight() -<<<<<<< HEAD -@image_comparison(['figure_suptitle_subfigures'], - extensions=['png']) -======= ->>>>>>> bb69a2fbc5 (RR - convert visual test to simple unit test.) def test_suptitle_subfigures(): fig = plt.figure(figsize=(4, 3)) sf1, sf2 = fig.subfigures(1, 2)