@@ -33,12 +33,10 @@ def __init__(self, fig, *args, **kwargs):
3333 **kwargs
3434 Keyword arguments are passed to the Axes (sub)class constructor.
3535 """
36-
37- self .figure = fig
38- self ._subplotspec = SubplotSpec ._from_subplot_args (fig , args )
39- self .update_params ()
4036 # _axes_class is set in the subplot_class_factory
41- self ._axes_class .__init__ (self , fig , self .figbox , ** kwargs )
37+ self ._axes_class .__init__ (self , fig , [0 , 0 , 1 , 1 ], ** kwargs )
38+ # This will also update the axes position.
39+ self .set_subplotspec (SubplotSpec ._from_subplot_args (fig , args ))
4240
4341 def __reduce__ (self ):
4442 # get the first axes class which does not inherit from a subplotbase
@@ -49,12 +47,15 @@ def __reduce__(self):
4947 (axes_class ,),
5048 self .__getstate__ ())
5149
50+ @cbook .deprecated (
51+ "3.4" , alternative = "get_subplotspec" ,
52+ addendum = "(get_subplotspec returns a SubplotSpec instance.)" )
5253 def get_geometry (self ):
5354 """Get the subplot geometry, e.g., (2, 2, 3)."""
5455 rows , cols , num1 , num2 = self .get_subplotspec ().get_geometry ()
5556 return rows , cols , num1 + 1 # for compatibility
5657
57- # COVERAGE NOTE: Never used internally or from examples
58+ @ cbook . deprecated ( "3.4" , alternative = "set_subplotspec" )
5859 def change_geometry (self , numrows , numcols , num ):
5960 """Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3)."""
6061 self ._subplotspec = GridSpec (numrows , numcols ,
@@ -69,16 +70,33 @@ def get_subplotspec(self):
6970 def set_subplotspec (self , subplotspec ):
7071 """Set the `.SubplotSpec`. instance associated with the subplot."""
7172 self ._subplotspec = subplotspec
73+ self ._set_position (subplotspec .get_position (self .figure ))
7274
7375 def get_gridspec (self ):
7476 """Return the `.GridSpec` instance associated with the subplot."""
7577 return self ._subplotspec .get_gridspec ()
7678
79+ @cbook .deprecated (
80+ "3.4" , alternative = "get_subplotspec().get_position(self.figure)" )
81+ @property
82+ def figbox (self ):
83+ return self .get_subplotspec ().get_position (self .figure )
84+
85+ @cbook .deprecated ("3.4" , alternative = "get_gridspec().nrows" )
86+ @property
87+ def numRows (self ):
88+ return self .get_gridspec ().nrows
89+
90+ @cbook .deprecated ("3.4" , alternative = "get_gridspec().ncols" )
91+ @property
92+ def numCols (self ):
93+ return self .get_gridspec ().ncols
94+
95+ @cbook .deprecated ("3.4" )
7796 def update_params (self ):
7897 """Update the subplot position from ``self.figure.subplotpars``."""
79- self .figbox , _ , _ , self .numRows , self .numCols = \
80- self .get_subplotspec ().get_position (self .figure ,
81- return_all = True )
98+ # Now a no-op, as figbox/numRows/numCols are (deprecated) auto-updating
99+ # properties.
82100
83101 @cbook .deprecated ("3.2" , alternative = "ax.get_subplotspec().rowspan.start" )
84102 @property
@@ -90,15 +108,19 @@ def rowNum(self):
90108 def colNum (self ):
91109 return self .get_subplotspec ().colspan .start
92110
111+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_first_row()" )
93112 def is_first_row (self ):
94113 return self .get_subplotspec ().rowspan .start == 0
95114
115+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_last_row()" )
96116 def is_last_row (self ):
97117 return self .get_subplotspec ().rowspan .stop == self .get_gridspec ().nrows
98118
119+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_first_col()" )
99120 def is_first_col (self ):
100121 return self .get_subplotspec ().colspan .start == 0
101122
123+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_last_col()" )
102124 def is_last_col (self ):
103125 return self .get_subplotspec ().colspan .stop == self .get_gridspec ().ncols
104126
@@ -109,8 +131,9 @@ def label_outer(self):
109131 x-labels are only kept for subplots on the last row; y-labels only for
110132 subplots on the first column.
111133 """
112- lastrow = self .is_last_row ()
113- firstcol = self .is_first_col ()
134+ ss = self .get_subplotspec ()
135+ lastrow = ss .is_last_row ()
136+ firstcol = ss .is_first_col ()
114137 if not lastrow :
115138 for label in self .get_xticklabels (which = "both" ):
116139 label .set_visible (False )
0 commit comments