Skip to content

Commit c13683a

Browse files
authored
Make default facecolor for subfigures be transparent ("none"). Fix for issue #24910 (#25255)
* RR - Set default facecolor for subfigures to be none (Transparent). Fixes issue #24910 * RR - Resolve merge conflict
1 parent 4de75b7 commit c13683a

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``SubFigure`` default facecolor is now transparent
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Subfigures default facecolor changed to ``"none"``. Previously the default was
5+
the value of ``figure.facecolor``.

lib/matplotlib/figure.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2155,8 +2155,8 @@ def __init__(self, parent, subplotspec, *,
21552155
Defines the region in a parent gridspec where the subfigure will
21562156
be placed.
21572157
2158-
facecolor : default: :rc:`figure.facecolor`
2159-
The figure patch face color.
2158+
facecolor : default: ``"none"``
2159+
The figure patch face color; transparent by default.
21602160
21612161
edgecolor : default: :rc:`figure.edgecolor`
21622162
The figure patch edge color.
@@ -2176,7 +2176,7 @@ def __init__(self, parent, subplotspec, *,
21762176
"""
21772177
super().__init__(**kwargs)
21782178
if facecolor is None:
2179-
facecolor = mpl.rcParams['figure.facecolor']
2179+
facecolor = "none"
21802180
if edgecolor is None:
21812181
edgecolor = mpl.rcParams['figure.edgecolor']
21822182
if frameon is None:

lib/matplotlib/tests/test_figure.py

+16
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ def test_suptitle_fontproperties():
287287
assert txt.get_weight() == fps.get_weight()
288288

289289

290+
def test_suptitle_subfigures():
291+
fig = plt.figure(figsize=(4, 3))
292+
sf1, sf2 = fig.subfigures(1, 2)
293+
sf2.set_facecolor('white')
294+
sf1.subplots()
295+
sf2.subplots()
296+
fig.suptitle("This is a visible suptitle.")
297+
298+
# verify the first subfigure facecolor is the default transparent
299+
assert sf1.get_facecolor() == (0.0, 0.0, 0.0, 0.0)
300+
# verify the second subfigure facecolor is white
301+
assert sf2.get_facecolor() == (1.0, 1.0, 1.0, 1.0)
302+
303+
290304
@image_comparison(['alpha_background'],
291305
# only test png and svg. The PDF output appears correct,
292306
# but Ghostscript does not preserve the background color.
@@ -1211,12 +1225,14 @@ def test_subfigure():
12111225
pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2, vmax=2)
12121226
sub[0].colorbar(pc, ax=axs)
12131227
sub[0].suptitle('Left Side')
1228+
sub[0].set_facecolor('white')
12141229

12151230
axs = sub[1].subplots(1, 3)
12161231
for ax in axs.flat:
12171232
pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2, vmax=2)
12181233
sub[1].colorbar(pc, ax=axs, location='bottom')
12191234
sub[1].suptitle('Right Side')
1235+
sub[1].set_facecolor('white')
12201236

12211237
fig.suptitle('Figure suptitle', fontsize='xx-large')
12221238

0 commit comments

Comments
 (0)