@@ -172,77 +172,82 @@ def __init__(self, left=None, bottom=None, right=None, top=None,
172172 wspace = None , hspace = None ):
173173 """
174174 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.* `.
176176
177177 Parameters
178178 ----------
179- left : float
179+ left : float, optional
180180 The left side of the subplots of the figure.
181181
182- right : float
182+ right : float, optional
183183 The right side of the subplots of the figure.
184184
185- bottom : float
185+ bottom : float, optional
186186 The bottom of the subplots of the figure.
187187
188- top : float
188+ top : float, optional
189189 The top of the subplots of the figure.
190190
191- wspace : float
191+ wspace : float, optional
192192 The amount of width reserved for space between subplots,
193193 expressed as a fraction of the average axis width.
194194
195- hspace : float
195+ hspace : float, optional
196196 The amount of height reserved for space between subplots,
197197 expressed as a fraction of the average axis height.
198198 """
199199 self .validate = True
200200 self .update (left , bottom , right , top , wspace , hspace )
201201
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+
202208 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 ()}
228219
220+ self ._update (varDict , rc_default )
229221 if self .validate :
230222 if self .left >= self .right :
231- reset ( )
223+ self . _update ( oldVarDict )
232224 raise ValueError ('left cannot be >= right' )
233225
234226 if self .bottom >= self .top :
235- reset ( )
227+ self . _update ( oldVarDict )
236228 raise ValueError ('bottom cannot be >= top' )
237229
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 ]
244238
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
246251
247252
248253class Figure (Artist ):
@@ -1400,8 +1405,11 @@ def clf(self, keep_observers=False):
14001405 """
14011406 Clear the figure.
14021407
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.
14051413 """
14061414 self .suppressComposite = None
14071415 self .callbacks = cbook .CallbackRegistry ()
@@ -1420,6 +1428,7 @@ def clf(self, keep_observers=False):
14201428 self .texts = []
14211429 self .images = []
14221430 self .legends = []
1431+ self .subplotpars .update (rc_default = True )
14231432 if not keep_observers :
14241433 self ._axobservers = []
14251434 self ._suptitle = None
@@ -1908,13 +1917,48 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
19081917 return cb
19091918
19101919 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 ):
19121921 """
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.
19151937
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.
19161958 """
1917- self .subplotpars .update (left , bottom , right , top , wspace , hspace )
1959+
1960+ self .subplotpars .update (left , bottom , right , top , wspace ,
1961+ hspace , rc_default )
19181962 for ax in self .axes :
19191963 if not isinstance (ax , SubplotBase ):
19201964 # Check if sharing a subplots axis
0 commit comments