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