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