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