Skip to content

Make default facecolor for subfigures be transparent ("none"). Fix for issue #24910 #25255

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

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/behavior/25255-RR.rst
Original file line number Diff line number Diff line change
@@ -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``.
6 changes: 3 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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')

Expand Down