@@ -33,12 +33,10 @@ def __init__(self, fig, *args, **kwargs):
33
33
**kwargs
34
34
Keyword arguments are passed to the Axes (sub)class constructor.
35
35
"""
36
-
37
- self .figure = fig
38
- self ._subplotspec = SubplotSpec ._from_subplot_args (fig , args )
39
- self .update_params ()
40
36
# _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 ))
42
40
43
41
def __reduce__ (self ):
44
42
# get the first axes class which does not inherit from a subplotbase
@@ -49,12 +47,15 @@ def __reduce__(self):
49
47
(axes_class ,),
50
48
self .__getstate__ ())
51
49
50
+ @cbook .deprecated (
51
+ "3.4" , alternative = "get_subplotspec" ,
52
+ addendum = "(get_subplotspec returns a SubplotSpec instance.)" )
52
53
def get_geometry (self ):
53
54
"""Get the subplot geometry, e.g., (2, 2, 3)."""
54
55
rows , cols , num1 , num2 = self .get_subplotspec ().get_geometry ()
55
56
return rows , cols , num1 + 1 # for compatibility
56
57
57
- # COVERAGE NOTE: Never used internally or from examples
58
+ @ cbook . deprecated ( "3.4" , alternative = "set_subplotspec" )
58
59
def change_geometry (self , numrows , numcols , num ):
59
60
"""Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3)."""
60
61
self ._subplotspec = GridSpec (numrows , numcols ,
@@ -69,16 +70,33 @@ def get_subplotspec(self):
69
70
def set_subplotspec (self , subplotspec ):
70
71
"""Set the `.SubplotSpec`. instance associated with the subplot."""
71
72
self ._subplotspec = subplotspec
73
+ self ._set_position (subplotspec .get_position (self .figure ))
72
74
73
75
def get_gridspec (self ):
74
76
"""Return the `.GridSpec` instance associated with the subplot."""
75
77
return self ._subplotspec .get_gridspec ()
76
78
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" )
77
96
def update_params (self ):
78
97
"""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.
82
100
83
101
@cbook .deprecated ("3.2" , alternative = "ax.get_subplotspec().rowspan.start" )
84
102
@property
@@ -90,15 +108,19 @@ def rowNum(self):
90
108
def colNum (self ):
91
109
return self .get_subplotspec ().colspan .start
92
110
111
+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_first_row()" )
93
112
def is_first_row (self ):
94
113
return self .get_subplotspec ().rowspan .start == 0
95
114
115
+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_last_row()" )
96
116
def is_last_row (self ):
97
117
return self .get_subplotspec ().rowspan .stop == self .get_gridspec ().nrows
98
118
119
+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_first_col()" )
99
120
def is_first_col (self ):
100
121
return self .get_subplotspec ().colspan .start == 0
101
122
123
+ @cbook .deprecated ("3.4" , alternative = "ax.get_subplotspec().is_last_col()" )
102
124
def is_last_col (self ):
103
125
return self .get_subplotspec ().colspan .stop == self .get_gridspec ().ncols
104
126
@@ -109,8 +131,9 @@ def label_outer(self):
109
131
x-labels are only kept for subplots on the last row; y-labels only for
110
132
subplots on the first column.
111
133
"""
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 ()
114
137
if not lastrow :
115
138
for label in self .get_xticklabels (which = "both" ):
116
139
label .set_visible (False )
0 commit comments