@@ -320,7 +320,7 @@ class GridSpec(GridSpecBase):
320
320
A grid layout to place subplots within a figure.
321
321
322
322
The location of the grid cells is determined in a similar way to
323
- `~.figure .SubplotParams` using *left*, *right*, *top*, *bottom*, *wspace*
323
+ `.SubplotParams` using *left*, *right*, *top*, *bottom*, *wspace*
324
324
and *hspace*.
325
325
326
326
Indexing a GridSpec instance returns a `.SubplotSpec`.
@@ -424,7 +424,7 @@ def get_subplot_params(self, figure=None):
424
424
if figure is None :
425
425
kw = {k : mpl .rcParams ["figure.subplot." + k ]
426
426
for k in self ._AllowedKeys }
427
- subplotpars = mpl . figure . SubplotParams (** kw )
427
+ subplotpars = SubplotParams (** kw )
428
428
else :
429
429
subplotpars = copy .copy (figure .subplotpars )
430
430
@@ -517,9 +517,9 @@ def get_subplot_params(self, figure=None):
517
517
figbox = self ._subplot_spec .get_position (figure )
518
518
left , bottom , right , top = figbox .extents
519
519
520
- return mpl . figure . SubplotParams (left = left , right = right ,
521
- bottom = bottom , top = top ,
522
- wspace = wspace , hspace = hspace )
520
+ return SubplotParams (left = left , right = right ,
521
+ bottom = bottom , top = top ,
522
+ wspace = wspace , hspace = hspace )
523
523
524
524
def get_topmost_subplotspec (self ):
525
525
"""
@@ -736,3 +736,63 @@ def subgridspec(self, nrows, ncols, **kwargs):
736
736
fig.add_subplot(gssub[0, i])
737
737
"""
738
738
return GridSpecFromSubplotSpec (nrows , ncols , self , ** kwargs )
739
+
740
+
741
+ class SubplotParams :
742
+ """
743
+ Parameters defining the positioning of a subplots grid in a figure.
744
+ """
745
+
746
+ def __init__ (self , left = None , bottom = None , right = None , top = None ,
747
+ wspace = None , hspace = None ):
748
+ """
749
+ Defaults are given by :rc:`figure.subplot.[name]`.
750
+
751
+ Parameters
752
+ ----------
753
+ left : float
754
+ The position of the left edge of the subplots,
755
+ as a fraction of the figure width.
756
+ right : float
757
+ The position of the right edge of the subplots,
758
+ as a fraction of the figure width.
759
+ bottom : float
760
+ The position of the bottom edge of the subplots,
761
+ as a fraction of the figure height.
762
+ top : float
763
+ The position of the top edge of the subplots,
764
+ as a fraction of the figure height.
765
+ wspace : float
766
+ The width of the padding between subplots,
767
+ as a fraction of the average Axes width.
768
+ hspace : float
769
+ The height of the padding between subplots,
770
+ as a fraction of the average Axes height.
771
+ """
772
+ for key in ["left" , "bottom" , "right" , "top" , "wspace" , "hspace" ]:
773
+ setattr (self , key , mpl .rcParams [f"figure.subplot.{ key } " ])
774
+ self .update (left , bottom , right , top , wspace , hspace )
775
+
776
+ def update (self , left = None , bottom = None , right = None , top = None ,
777
+ wspace = None , hspace = None ):
778
+ """
779
+ Update the dimensions of the passed parameters. *None* means unchanged.
780
+ """
781
+ if ((left if left is not None else self .left )
782
+ >= (right if right is not None else self .right )):
783
+ raise ValueError ('left cannot be >= right' )
784
+ if ((bottom if bottom is not None else self .bottom )
785
+ >= (top if top is not None else self .top )):
786
+ raise ValueError ('bottom cannot be >= top' )
787
+ if left is not None :
788
+ self .left = left
789
+ if right is not None :
790
+ self .right = right
791
+ if bottom is not None :
792
+ self .bottom = bottom
793
+ if top is not None :
794
+ self .top = top
795
+ if wspace is not None :
796
+ self .wspace = wspace
797
+ if hspace is not None :
798
+ self .hspace = hspace
0 commit comments