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..94b86651e749 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"`` + The figure patch face color; transparent by default. 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..80d80f969163 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -287,6 +287,20 @@ def test_suptitle_fontproperties(): assert txt.get_weight() == fps.get_weight() +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 +1225,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')