@@ -172,77 +172,81 @@ def __init__(self, left=None, bottom=None, right=None, top=None,
172
172
wspace = None , hspace = None ):
173
173
"""
174
174
All dimensions are fractions of the figure width or height.
175
- Defaults are given by :rc:`figure.subplot.[name] `.
175
+ Defaults are given by :rc:`figure.subplot.* `.
176
176
177
177
Parameters
178
178
----------
179
- left : float
179
+ left : float, optional
180
180
The left side of the subplots of the figure.
181
181
182
- right : float
182
+ right : float, optional
183
183
The right side of the subplots of the figure.
184
184
185
- bottom : float
185
+ bottom : float, optional
186
186
The bottom of the subplots of the figure.
187
187
188
- top : float
188
+ top : float, optional
189
189
The top of the subplots of the figure.
190
190
191
- wspace : float
191
+ wspace : float, optional
192
192
The amount of width reserved for space between subplots,
193
193
expressed as a fraction of the average axis width.
194
194
195
- hspace : float
195
+ hspace : float, optional
196
196
The amount of height reserved for space between subplots,
197
197
expressed as a fraction of the average axis height.
198
198
"""
199
199
self .validate = True
200
200
self .update (left , bottom , right , top , wspace , hspace )
201
201
202
+ def __repr__ (self ):
203
+ return ("SubplotParams(left={}, bottom={}, right={}, top={}, "
204
+ "wspace={}, hspace={})" ).format (
205
+ self .left , self .bottom , self .right , self .top ,
206
+ self .wspace , self .hspace )
207
+
202
208
def update (self , left = None , bottom = None , right = None , top = None ,
203
- wspace = None , hspace = None ):
204
- """
205
- Update the dimensions of the passed parameters. *None* means unchanged.
206
- """
207
- thisleft = getattr (self , 'left' , None )
208
- thisright = getattr (self , 'right' , None )
209
- thistop = getattr (self , 'top' , None )
210
- thisbottom = getattr (self , 'bottom' , None )
211
- thiswspace = getattr (self , 'wspace' , None )
212
- thishspace = getattr (self , 'hspace' , None )
213
-
214
- self ._update_this ('left' , left )
215
- self ._update_this ('right' , right )
216
- self ._update_this ('bottom' , bottom )
217
- self ._update_this ('top' , top )
218
- self ._update_this ('wspace' , wspace )
219
- self ._update_this ('hspace' , hspace )
220
-
221
- def reset ():
222
- self .left = thisleft
223
- self .right = thisright
224
- self .top = thistop
225
- self .bottom = thisbottom
226
- self .wspace = thiswspace
227
- self .hspace = thishspace
209
+ wspace = None , hspace = None , rc_default = False ):
210
+ """
211
+ Update the dimensions of the passed parameters. *None* means
212
+ unchanged if the attribute is set and *rc_default* is *False*, and
213
+ :rc:`figure.subplot.*` otherwise.
214
+ """
215
+
216
+ varDict = dict (left = left , bottom = bottom , right = right , top = top ,
217
+ wspace = wspace , hspace = hspace )
218
+ oldVarDict = {key : getattr (self , key , None ) for key in varDict .keys ()}
228
219
220
+ self ._update (varDict , rc_default )
229
221
if self .validate :
230
222
if self .left >= self .right :
231
- reset ( )
223
+ self . _update ( oldVarDict )
232
224
raise ValueError ('left cannot be >= right' )
233
225
234
226
if self .bottom >= self .top :
235
- reset ( )
227
+ self . _update ( oldVarDict )
236
228
raise ValueError ('bottom cannot be >= top' )
237
229
238
- def _update_this (self , s , val ):
239
- if val is None :
240
- val = getattr (self , s , None )
241
- if val is None :
242
- key = 'figure.subplot.' + s
243
- val = rcParams [key ]
230
+ def _update (self , varDict , rc_default = None ):
231
+ for att , value in varDict .items ():
232
+ if value is None :
233
+ if not rc_default :
234
+ value = getattr (self , att , None )
235
+ if value is None :
236
+ key = 'figure.subplot.' + att
237
+ value = rcParams [key ]
244
238
245
- setattr (self , s , val )
239
+ setattr (self , att , value )
240
+
241
+ def get_subplot_params (self ):
242
+ """
243
+ Returns
244
+ -------
245
+ A dictionary with the subplot parameters
246
+ """
247
+ subplot_params = self .__dict__ .copy ()
248
+ del subplot_params ['validate' ]
249
+ return subplot_params
246
250
247
251
248
252
class Figure (Artist ):
@@ -1396,8 +1400,11 @@ def clf(self, keep_observers=False):
1396
1400
"""
1397
1401
Clear the figure.
1398
1402
1399
- Set *keep_observers* to True if, for example,
1400
- a gui widget is tracking the axes in the figure.
1403
+ Parameters
1404
+ ----------
1405
+ keep_observers : bool, optional
1406
+ Set *keep_observers* to True if, for example,
1407
+ a gui widget is tracking the axes in the figure.
1401
1408
"""
1402
1409
self .suppressComposite = None
1403
1410
self .callbacks = cbook .CallbackRegistry ()
@@ -1416,6 +1423,7 @@ def clf(self, keep_observers=False):
1416
1423
self .texts = []
1417
1424
self .images = []
1418
1425
self .legends = []
1426
+ self .subplotpars .update (rc_default = True )
1419
1427
if not keep_observers :
1420
1428
self ._axobservers = []
1421
1429
self ._suptitle = None
@@ -1904,13 +1912,48 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
1904
1912
return cb
1905
1913
1906
1914
def subplots_adjust (self , left = None , bottom = None , right = None , top = None ,
1907
- wspace = None , hspace = None ):
1915
+ wspace = None , hspace = None , rc_default = False ):
1908
1916
"""
1909
- Update the :class:`SubplotParams` with *kwargs* (defaulting to rc when
1910
- *None*) and update the subplot locations.
1917
+ Tune the subplots layout by updating the subplots parameters and
1918
+ the subplot locations.
1919
+
1920
+ All dimensions are fractions of the figure width or height.
1921
+
1922
+ Parameters
1923
+ ----------
1924
+ left : float, optional
1925
+ The left side of the subplots of the figure.
1926
+
1927
+ right : float, optional
1928
+ The right side of the subplots of the figure.
1929
+
1930
+ bottom : float, optional
1931
+ The bottom of the subplots of the figure.
1911
1932
1933
+ top : float, optional
1934
+ The top of the subplots of the figure.
1935
+
1936
+ wspace : float, optional
1937
+ The amount of width reserved for space between subplots,
1938
+ expressed as a fraction of the average axis width.
1939
+
1940
+ hspace : float, optional
1941
+ The amount of height reserved for space between subplots,
1942
+ expressed as a fraction of the average axis height.
1943
+
1944
+ rc_default : bool, optional
1945
+ Determine the defaults. *False*, the default, and the values
1946
+ are unchanged. *True* and the values are taken from
1947
+ :rc:`figure.subplot.*`
1948
+
1949
+ Notes
1950
+ -----
1951
+ The subplots parameters are stored in the `~.Figure` attribute
1952
+ ``subplotpars`` as a `~.SubplotParams` object.
1912
1953
"""
1913
- self .subplotpars .update (left , bottom , right , top , wspace , hspace )
1954
+
1955
+ self .subplotpars .update (left , bottom , right , top , wspace ,
1956
+ hspace , rc_default )
1914
1957
for ax in self .axes :
1915
1958
if not isinstance (ax , SubplotBase ):
1916
1959
# Check if sharing a subplots axis
0 commit comments