Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3e864c

Browse files
authored
Merge pull request #15200 from anntzer/subplotpars
Simplify SubplotParams.update().
2 parents ee26217 + 397d5b7 commit e3e864c

File tree

1 file changed

+30
-50
lines changed

1 file changed

+30
-50
lines changed

lib/matplotlib/figure.py

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -168,78 +168,58 @@ class SubplotParams:
168168
def __init__(self, left=None, bottom=None, right=None, top=None,
169169
wspace=None, hspace=None):
170170
"""
171-
All dimensions are fractions of the figure width or height.
172171
Defaults are given by :rc:`figure.subplot.[name]`.
173172
174173
Parameters
175174
----------
176175
left : float
177-
The left side of the subplots of the figure.
178-
176+
The position of the left edge of the subplots,
177+
as a fraction of the figure width.
179178
right : float
180-
The right side of the subplots of the figure.
181-
179+
The position of the right edge of the subplots,
180+
as a fraction of the figure width.
182181
bottom : float
183-
The bottom of the subplots of the figure.
184-
182+
The position of the bottom edge of the subplots,
183+
as a fraction of the figure height.
185184
top : float
186-
The top of the subplots of the figure.
187-
185+
The position of the top edge of the subplots,
186+
as a fraction of the figure height.
188187
wspace : float
189-
The amount of width reserved for space between subplots,
190-
expressed as a fraction of the average axis width.
191-
188+
The width of the padding between subplots,
189+
as a fraction of the average axes width.
192190
hspace : float
193-
The amount of height reserved for space between subplots,
194-
expressed as a fraction of the average axis height.
191+
The height of the padding between subplots,
192+
as a fraction of the average axes height.
195193
"""
196194
self.validate = True
195+
for key in ["left", "bottom", "right", "top", "wspace", "hspace"]:
196+
setattr(self, key, rcParams[f"figure.subplot.{key}"])
197197
self.update(left, bottom, right, top, wspace, hspace)
198198

199199
def update(self, left=None, bottom=None, right=None, top=None,
200200
wspace=None, hspace=None):
201201
"""
202202
Update the dimensions of the passed parameters. *None* means unchanged.
203203
"""
204-
thisleft = getattr(self, 'left', None)
205-
thisright = getattr(self, 'right', None)
206-
thistop = getattr(self, 'top', None)
207-
thisbottom = getattr(self, 'bottom', None)
208-
thiswspace = getattr(self, 'wspace', None)
209-
thishspace = getattr(self, 'hspace', None)
210-
211-
self._update_this('left', left)
212-
self._update_this('right', right)
213-
self._update_this('bottom', bottom)
214-
self._update_this('top', top)
215-
self._update_this('wspace', wspace)
216-
self._update_this('hspace', hspace)
217-
218-
def reset():
219-
self.left = thisleft
220-
self.right = thisright
221-
self.top = thistop
222-
self.bottom = thisbottom
223-
self.wspace = thiswspace
224-
self.hspace = thishspace
225-
226204
if self.validate:
227-
if self.left >= self.right:
228-
reset()
205+
if ((left if left is not None else self.left)
206+
>= (right if right is not None else self.right)):
229207
raise ValueError('left cannot be >= right')
230-
231-
if self.bottom >= self.top:
232-
reset()
208+
if ((bottom if bottom is not None else self.bottom)
209+
>= (top if top is not None else self.top)):
233210
raise ValueError('bottom cannot be >= top')
234-
235-
def _update_this(self, s, val):
236-
if val is None:
237-
val = getattr(self, s, None)
238-
if val is None:
239-
key = 'figure.subplot.' + s
240-
val = rcParams[key]
241-
242-
setattr(self, s, val)
211+
if left is not None:
212+
self.left = left
213+
if right is not None:
214+
self.right = right
215+
if bottom is not None:
216+
self.bottom = bottom
217+
if top is not None:
218+
self.top = top
219+
if wspace is not None:
220+
self.wspace = wspace
221+
if hspace is not None:
222+
self.hspace = hspace
243223

244224

245225
class Figure(Artist):

0 commit comments

Comments
 (0)