Skip to content

Commit aa740f3

Browse files
committed
remove usage of rc_default
1 parent ddcc0b4 commit aa740f3

File tree

7 files changed

+16
-31
lines changed

7 files changed

+16
-31
lines changed

lib/matplotlib/figure.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def clear(self, keep_observers=False):
989989
self.texts = []
990990
self.images = []
991991
self.legends = []
992-
self.subplotpars.update(rc_default=True)
992+
self.subplotpars.reset()
993993
if not keep_observers:
994994
self._axobservers = cbook.CallbackRegistry()
995995
self._suptitle = None
@@ -1312,7 +1312,7 @@ def colorbar(
13121312
return cb
13131313

13141314
def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
1315-
wspace=None, hspace=None, rc_default=False):
1315+
wspace=None, hspace=None):
13161316
"""
13171317
Adjust the subplot layout parameters.
13181318
@@ -1341,10 +1341,6 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
13411341
hspace : float, optional
13421342
The height of the padding between subplots,
13431343
as a fraction of the average Axes height.
1344-
rc_default : bool
1345-
Determine the defaults. *False*, the default, and the values
1346-
are unchanged. *True* and the values are taken from
1347-
:rc:`figure.subplot.*`
13481344
"""
13491345
if (self.get_layout_engine() is not None and
13501346
not self.get_layout_engine().adjust_compatible):
@@ -1353,8 +1349,7 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
13531349
"incompatible with subplots_adjust and/or tight_layout; "
13541350
"not calling subplots_adjust.")
13551351
return
1356-
self.subplotpars.update(left, bottom, right, top, wspace, hspace,
1357-
rc_default=rc_default)
1352+
self.subplotpars.update(left, bottom, right, top, wspace, hspace)
13581353
for ax in self.axes:
13591354
if ax.get_subplotspec() is not None:
13601355
ax._set_position(ax.get_subplotspec().get_position(self))

lib/matplotlib/figure.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ class FigureBase(Artist):
179179
top: float | None = ...,
180180
wspace: float | None = ...,
181181
hspace: float | None = ...,
182-
rc_default: bool = ...,
183182
) -> None: ...
184183
def align_xlabels(self, axs: Iterable[Axes] | None = ...) -> None: ...
185184
def align_ylabels(self, axs: Iterable[Axes] | None = ...) -> None: ...

lib/matplotlib/gridspec.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,9 @@ def _repr_pretty_(self, p: Any, cycle: bool) -> None:
771771
p.text(s)
772772

773773
def update(self, left=None, bottom=None, right=None, top=None,
774-
wspace=None, hspace=None, rc_default=False):
774+
wspace=None, hspace=None):
775775
"""
776776
Update the dimensions of the passed parameters. *None* means unchanged.
777-
If *rc_default* is True, then restore the parameters with value *None*
778-
to the default.
779777
"""
780778
if ((left if left is not None else self.left)
781779
>= (right if right is not None else self.right)):
@@ -787,12 +785,14 @@ def update(self, left=None, bottom=None, right=None, top=None,
787785
attributes = {'left': left, 'right': right, 'bottom': bottom, 'top': top,
788786
'hspace': hspace, 'wspace': wspace}
789787
for key, value in attributes.items():
790-
if value is None:
791-
if rc_default:
792-
setattr(self, key, mpl.rcParams[f'figure.subplot.{key}'])
793-
else:
788+
if value is not None:
794789
setattr(self, key, value)
795790

791+
def reset(self):
792+
""" Restore the positioning parameters to the default values """
793+
for key in self.get_subplot_params.keys():
794+
setattr(self, key, mpl.rcParams[f'figure.subplot.{key}'])
795+
796796
def get_subplot_params(self) -> dict[str, float]:
797797
"""
798798
Returns

lib/matplotlib/gridspec.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class SubplotParams:
157157
top: float | None = ...,
158158
wspace: float | None = ...,
159159
hspace: float | None = ...,
160-
rc_default: bool = ...,
161160
) -> None: ...
162161
def get_subplot_params(
163162
self,

lib/matplotlib/pyplot.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -2826,16 +2826,9 @@ def subplots_adjust(
28262826
top: float | None = None,
28272827
wspace: float | None = None,
28282828
hspace: float | None = None,
2829-
rc_default: bool = False,
28302829
) -> None:
28312830
gcf().subplots_adjust(
2832-
left=left,
2833-
bottom=bottom,
2834-
right=right,
2835-
top=top,
2836-
wspace=wspace,
2837-
hspace=hspace,
2838-
rc_default=rc_default,
2831+
left=left, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace
28392832
)
28402833

28412834

lib/matplotlib/tests/test_figure.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1793,22 +1793,18 @@ def test_suplots_adjust_1():
17931793
def test_suplots_adjust_2():
17941794
fig = plt.figure(1)
17951795
fig.subplots_adjust(wspace=0)
1796-
inDict = dict(left=0.1, right=0.7, bottom=0, top=0.9, hspace=0.05,
1797-
rc_default=True)
1796+
inDict = dict(left=0.1, right=0.7, bottom=0, top=0.9, hspace=0.05)
17981797
fig.subplots_adjust(**inDict)
17991798
inDict['wspace'] = plt.rcParams['figure.subplot.wspace']
1800-
del inDict['rc_default']
18011799
assert fig.subplotpars.get_subplot_params() == inDict
18021800

18031801

18041802
def test_suplots_adjust_plt():
18051803
plt.figure(1)
18061804
plt.subplots_adjust(wspace=0)
1807-
inDict = dict(left=0.1, right=0.7, bottom=0, top=0.9, hspace=0.05,
1808-
rc_default=True)
1805+
inDict = dict(left=0.1, right=0.7, bottom=0, top=0.9, hspace=0.05)
18091806
plt.subplots_adjust(**inDict)
18101807
inDict['wspace'] = plt.rcParams['figure.subplot.wspace']
1811-
del inDict['rc_default']
18121808
assert plt.gcf().subplotpars.get_subplot_params() == inDict
18131809

18141810

lib/matplotlib/tests/test_gridspec.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import matplotlib
23
import matplotlib.gridspec as gridspec
34
import matplotlib.pyplot as plt
45
import pytest
@@ -51,6 +52,8 @@ def test_SubplotParams():
5152
with pytest.raises(ValueError):
5253
s = gridspec.SubplotParams(.1, .1, .09, .9)
5354

55+
s.reset()
56+
assert s.left == matplotlib.rcParams['figure.subplot.left']
5457

5558
def test_repr():
5659
ss = gridspec.GridSpec(3, 3)[2, 1:3]

0 commit comments

Comments
 (0)