@@ -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 ):
@@ -1400,8 +1404,11 @@ def clf(self, keep_observers=False):
1400
1404
"""
1401
1405
Clear the figure.
1402
1406
1403
- Set *keep_observers* to True if, for example,
1404
- a gui widget is tracking the axes in the figure.
1407
+ Parameters
1408
+ ---------
1409
+ keep_observers : bool, optional
1410
+ Set *keep_observers* to True if, for example,
1411
+ a gui widget is tracking the axes in the figure.
1405
1412
"""
1406
1413
self .suppressComposite = None
1407
1414
self .callbacks = cbook .CallbackRegistry ()
@@ -1420,6 +1427,7 @@ def clf(self, keep_observers=False):
1420
1427
self .texts = []
1421
1428
self .images = []
1422
1429
self .legends = []
1430
+ self .subplotpars .update (rc_default = True )
1423
1431
if not keep_observers :
1424
1432
self ._axobservers = []
1425
1433
self ._suptitle = None
@@ -1908,13 +1916,47 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
1908
1916
return cb
1909
1917
1910
1918
def subplots_adjust (self , left = None , bottom = None , right = None , top = None ,
1911
- wspace = None , hspace = None ):
1919
+ wspace = None , hspace = None , rc_default = False ):
1912
1920
"""
1913
- Update the :class:`SubplotParams` with *kwargs* (defaulting to rc when
1914
- *None*) and update the subplot locations.
1921
+ Tune the subplots layout by updating the subplots parameters and
1922
+ the subplot locations.
1923
+
1924
+ All dimensions are fractions of the figure width or height.
1925
+
1926
+ Parameters
1927
+ ----------
1928
+ left : float, optional
1929
+ The left side of the subplots of the figure.
1915
1930
1931
+ right : float, optional
1932
+ The right side of the subplots of the figure.
1933
+
1934
+ bottom : float, optional
1935
+ The bottom of the subplots of the figure.
1936
+
1937
+ top : float, optional
1938
+ The top of the subplots of the figure.
1939
+
1940
+ wspace : float, optional
1941
+ The amount of width reserved for space between subplots,
1942
+ expressed as a fraction of the average axis width.
1943
+
1944
+ hspace : float, optional
1945
+ The amount of height reserved for space between subplots,
1946
+ expressed as a fraction of the average axis height.
1947
+
1948
+ rc_default : bool, optional
1949
+ Determine the defaults. *True* and the default is taken from
1950
+ :rc:`figure.subplot.*`, *False* and the value is unchanged.
1951
+
1952
+ Notes
1953
+ -----
1954
+ The subplots parameters are stored in the `~.Figure` attribute
1955
+ ``subplotpars`` as a `~.SubplotParams` object.
1916
1956
"""
1917
- self .subplotpars .update (left , bottom , right , top , wspace , hspace )
1957
+
1958
+ self .subplotpars .update (left , bottom , right , top , wspace ,
1959
+ hspace , rc_default )
1918
1960
for ax in self .axes :
1919
1961
if not isinstance (ax , SubplotBase ):
1920
1962
# Check if sharing a subplots axis
0 commit comments