@@ -188,7 +188,8 @@ def get_xlabel(self):
188188 label = self .xaxis .get_label ()
189189 return label .get_text ()
190190
191- def set_xlabel (self , xlabel , fontdict = None , labelpad = None , ** kwargs ):
191+ def set_xlabel (self , xlabel , fontdict = None , labelpad = None , * ,
192+ loc = None , ** kwargs ):
192193 """
193194 Set the label for the x-axis.
194195
@@ -201,6 +202,10 @@ def set_xlabel(self, xlabel, fontdict=None, labelpad=None, **kwargs):
201202 Spacing in points from the axes bounding box including ticks
202203 and tick labels.
203204
205+ loc : {'left', 'center', 'right'}, default: :rc:`xaxis.labellocation`
206+ The label position. This is a high-level alternative for passing
207+ parameters *x* and *horizonatalalignment*.
208+
204209 Other Parameters
205210 ----------------
206211 **kwargs : `.Text` properties
@@ -212,6 +217,22 @@ def set_xlabel(self, xlabel, fontdict=None, labelpad=None, **kwargs):
212217 """
213218 if labelpad is not None :
214219 self .xaxis .labelpad = labelpad
220+ _protected_kw = ['x' , 'horizontalalignment' , 'ha' ]
221+ if any ([k in kwargs for k in _protected_kw ]):
222+ if loc is not None :
223+ raise TypeError ('Specifying *loc* is disallowed when any of '
224+ 'its corresponding low level kwargs {} '
225+ 'are supplied as well.' .format (_protected_kw ))
226+ loc = 'center'
227+ else :
228+ loc = loc if loc is not None else rcParams ['xaxis.labellocation' ]
229+ cbook ._check_in_list (('left' , 'center' , 'right' ), loc = loc )
230+ if loc == 'right' :
231+ kwargs ['x' ] = 1.
232+ kwargs ['horizontalalignment' ] = 'right'
233+ elif loc == 'left' :
234+ kwargs ['x' ] = 0.
235+ kwargs ['horizontalalignment' ] = 'left'
215236 return self .xaxis .set_label_text (xlabel , fontdict , ** kwargs )
216237
217238 def get_ylabel (self ):
@@ -221,7 +242,8 @@ def get_ylabel(self):
221242 label = self .yaxis .get_label ()
222243 return label .get_text ()
223244
224- def set_ylabel (self , ylabel , fontdict = None , labelpad = None , ** kwargs ):
245+ def set_ylabel (self , ylabel , fontdict = None , labelpad = None , * ,
246+ loc = None , ** kwargs ):
225247 """
226248 Set the label for the y-axis.
227249
@@ -234,6 +256,10 @@ def set_ylabel(self, ylabel, fontdict=None, labelpad=None, **kwargs):
234256 Spacing in points from the axes bounding box including ticks
235257 and tick labels.
236258
259+ loc : {'bottom', 'center', 'top'}, default: :rc:`yaxis.labellocation`
260+ The label position. This is a high-level alternative for passing
261+ parameters *y* and *horizonatalalignment*.
262+
237263 Other Parameters
238264 ----------------
239265 **kwargs : `.Text` properties
@@ -246,6 +272,22 @@ def set_ylabel(self, ylabel, fontdict=None, labelpad=None, **kwargs):
246272 """
247273 if labelpad is not None :
248274 self .yaxis .labelpad = labelpad
275+ _protected_kw = ['y' , 'horizontalalignment' , 'ha' ]
276+ if any ([k in kwargs for k in _protected_kw ]):
277+ if loc is not None :
278+ raise TypeError ('Specifying *loc* is disallowed when any of '
279+ 'its corresponding low level kwargs {} '
280+ 'are supplied as well.' .format (_protected_kw ))
281+ loc = 'center'
282+ else :
283+ loc = loc if loc is not None else rcParams ['yaxis.labellocation' ]
284+ cbook ._check_in_list (('bottom' , 'center' , 'top' ), loc = loc )
285+ if loc == 'top' :
286+ kwargs ['y' ] = 1.
287+ kwargs ['horizontalalignment' ] = 'right'
288+ elif loc == 'bottom' :
289+ kwargs ['y' ] = 0.
290+ kwargs ['horizontalalignment' ] = 'left'
249291 return self .yaxis .set_label_text (ylabel , fontdict , ** kwargs )
250292
251293 def get_legend_handles_labels (self , legend_handler_map = None ):
0 commit comments