@@ -117,22 +117,44 @@ def label_outer(self):
117
117
"""
118
118
Only show "outer" labels and tick labels.
119
119
120
- x-labels are only kept for subplots on the last row; y-labels only for
121
- subplots on the first column.
120
+ x-labels are only kept for subplots on the last row (or first row, if
121
+ labels are on the top side); y-labels only for subplots on the first
122
+ column (or last column, if labels are on the right side).
122
123
"""
124
+ self ._label_outer_xaxis ()
125
+ self ._label_outer_yaxis ()
126
+
127
+ def _label_outer_xaxis (self ):
128
+ ss = self .get_subplotspec ()
129
+ label_position = self .xaxis .get_label_position ()
130
+ if not ss .is_first_row (): # Remove top label/ticklabels/offsettext.
131
+ if label_position == "top" :
132
+ self .set_xlabel ("" )
133
+ self .xaxis .set_tick_params (which = "both" , labeltop = False )
134
+ if self .xaxis .offsetText .get_position ()[1 ] == 1 :
135
+ self .xaxis .offsetText .set_visible (False )
136
+ if not ss .is_last_row (): # Remove bottom label/ticklabels/offsettext.
137
+ if label_position == "bottom" :
138
+ self .set_xlabel ("" )
139
+ self .xaxis .set_tick_params (which = "both" , labelbottom = False )
140
+ if self .xaxis .offsetText .get_position ()[1 ] == 0 :
141
+ self .xaxis .offsetText .set_visible (False )
142
+
143
+ def _label_outer_yaxis (self ):
123
144
ss = self .get_subplotspec ()
124
- lastrow = ss .is_last_row ()
125
- firstcol = ss .is_first_col ()
126
- if not lastrow :
127
- for label in self .get_xticklabels (which = "both" ):
128
- label .set_visible (False )
129
- self .xaxis .get_offset_text ().set_visible (False )
130
- self .set_xlabel ("" )
131
- if not firstcol :
132
- for label in self .get_yticklabels (which = "both" ):
133
- label .set_visible (False )
134
- self .yaxis .get_offset_text ().set_visible (False )
135
- self .set_ylabel ("" )
145
+ label_position = self .xaxis .get_label_position ()
146
+ if not ss .is_first_col (): # Remove left label/ticklabels/offsettext.
147
+ if label_position == "left" :
148
+ self .set_xlabel ("" )
149
+ self .yaxis .set_tick_params (which = "both" , labelleft = False )
150
+ if self .yaxis .offsetText .get_position ()[0 ] == 0 :
151
+ self .yaxis .offsetText .set_visible (False )
152
+ if not ss .is_last_col (): # Remove right label/ticklabels/offsettext.
153
+ if label_position == "right" :
154
+ self .set_xlabel ("" )
155
+ self .yaxis .set_tick_params (which = "both" , labelright = False )
156
+ if self .yaxis .offsetText .get_position ()[0 ] == 1 :
157
+ self .yaxis .offsetText .set_visible (False )
136
158
137
159
def _make_twin_axes (self , * args , ** kwargs ):
138
160
"""Make a twinx axes of self. This is used for twinx and twiny."""
0 commit comments