@@ -173,77 +173,81 @@ def __init__(self, left=None, bottom=None, right=None, top=None,
173173 wspace = None , hspace = None ):
174174 """
175175 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.* `.
177177
178178 Parameters
179179 ----------
180- left : float
180+ left : float, optional
181181 The left side of the subplots of the figure.
182182
183- right : float
183+ right : float, optional
184184 The right side of the subplots of the figure.
185185
186- bottom : float
186+ bottom : float, optional
187187 The bottom of the subplots of the figure.
188188
189- top : float
189+ top : float, optional
190190 The top of the subplots of the figure.
191191
192- wspace : float
192+ wspace : float, optional
193193 The amount of width reserved for space between subplots,
194194 expressed as a fraction of the average axis width.
195195
196- hspace : float
196+ hspace : float, optional
197197 The amount of height reserved for space between subplots,
198198 expressed as a fraction of the average axis height.
199199 """
200200 self .validate = True
201201 self .update (left , bottom , right , top , wspace , hspace )
202202
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+
203209 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 ()}
229220
221+ self ._update (varDict , rc_default )
230222 if self .validate :
231223 if self .left >= self .right :
232- reset ( )
224+ self . _update ( oldVarDict )
233225 raise ValueError ('left cannot be >= right' )
234226
235227 if self .bottom >= self .top :
236- reset ( )
228+ self . _update ( oldVarDict )
237229 raise ValueError ('bottom cannot be >= top' )
238230
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 ]
245239
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
247251
248252
249253class Figure (Artist ):
@@ -1406,8 +1410,11 @@ def clf(self, keep_observers=False):
14061410 """
14071411 Clear the figure.
14081412
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.
14111418 """
14121419 self .suppressComposite = None
14131420 self .callbacks = cbook .CallbackRegistry ()
@@ -1426,6 +1433,7 @@ def clf(self, keep_observers=False):
14261433 self .texts = []
14271434 self .images = []
14281435 self .legends = []
1436+ self .subplotpars .update (rc_default = True )
14291437 if not keep_observers :
14301438 self ._axobservers = []
14311439 self ._suptitle = None
@@ -1915,13 +1923,48 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
19151923 return cb
19161924
19171925 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 ):
19191927 """
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.
19221943
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.
19231964 """
1924- self .subplotpars .update (left , bottom , right , top , wspace , hspace )
1965+
1966+ self .subplotpars .update (left , bottom , right , top , wspace ,
1967+ hspace , rc_default )
19251968 for ax in self .axes :
19261969 if not isinstance (ax , SubplotBase ):
19271970 # Check if sharing a subplots axis
0 commit comments