@@ -3127,6 +3127,60 @@ def set_axis_on(self):
31273127
31283128 # data limits, ticks, tick labels, and formatting
31293129
3130+ def get_xlabel (self ):
3131+ """
3132+ Get the xlabel text string.
3133+ """
3134+ label = self .xaxis .get_label ()
3135+ return label .get_text ()
3136+
3137+ def set_xlabel (self , xlabel , fontdict = None , labelpad = None , * ,
3138+ loc = None , ** kwargs ):
3139+ """
3140+ Set the label for the x-axis.
3141+
3142+ Parameters
3143+ ----------
3144+ xlabel : str
3145+ The label text.
3146+
3147+ labelpad : float, default: None
3148+ Spacing in points from the axes bounding box including ticks
3149+ and tick labels.
3150+
3151+ loc : {'left', 'center', 'right'}, default: :rc:`xaxis.labellocation`
3152+ The label position. This is a high-level alternative for passing
3153+ parameters *x* and *horizontalalignment*.
3154+
3155+ Other Parameters
3156+ ----------------
3157+ **kwargs : `.Text` properties
3158+ `.Text` properties control the appearance of the label.
3159+
3160+ See Also
3161+ --------
3162+ text : Documents the properties supported by `.Text`.
3163+ """
3164+ if labelpad is not None :
3165+ self .xaxis .labelpad = labelpad
3166+ protected_kw = ['x' , 'horizontalalignment' , 'ha' ]
3167+ if {* kwargs } & {* protected_kw }:
3168+ if loc is not None :
3169+ raise TypeError (f"Specifying 'loc' is disallowed when any of "
3170+ f"its corresponding low level keyword "
3171+ f"arguments ({ protected_kw } ) are also "
3172+ f"supplied" )
3173+ loc = 'center'
3174+ else :
3175+ loc = (loc if loc is not None
3176+ else mpl .rcParams ['xaxis.labellocation' ])
3177+ cbook ._check_in_list (('left' , 'center' , 'right' ), loc = loc )
3178+ if loc == 'left' :
3179+ kwargs .update (x = 0 , horizontalalignment = 'left' )
3180+ elif loc == 'right' :
3181+ kwargs .update (x = 1 , horizontalalignment = 'right' )
3182+ return self .xaxis .set_label_text (xlabel , fontdict , ** kwargs )
3183+
31303184 def invert_xaxis (self ):
31313185 """
31323186 Invert the x-axis.
@@ -3416,6 +3470,60 @@ def set_xscale(self, value, **kwargs):
34163470 "xaxis" , "_set_ticklabels" ,
34173471 doc_sub = {"Axis.set_ticks" : "Axes.set_xticks" })
34183472
3473+ def get_ylabel (self ):
3474+ """
3475+ Get the ylabel text string.
3476+ """
3477+ label = self .yaxis .get_label ()
3478+ return label .get_text ()
3479+
3480+ def set_ylabel (self , ylabel , fontdict = None , labelpad = None , * ,
3481+ loc = None , ** kwargs ):
3482+ """
3483+ Set the label for the y-axis.
3484+
3485+ Parameters
3486+ ----------
3487+ ylabel : str
3488+ The label text.
3489+
3490+ labelpad : float, default: None
3491+ Spacing in points from the axes bounding box including ticks
3492+ and tick labels.
3493+
3494+ loc : {'bottom', 'center', 'top'}, default: :rc:`yaxis.labellocation`
3495+ The label position. This is a high-level alternative for passing
3496+ parameters *y* and *horizontalalignment*.
3497+
3498+ Other Parameters
3499+ ----------------
3500+ **kwargs : `.Text` properties
3501+ `.Text` properties control the appearance of the label.
3502+
3503+ See Also
3504+ --------
3505+ text : Documents the properties supported by `.Text`.
3506+ """
3507+ if labelpad is not None :
3508+ self .yaxis .labelpad = labelpad
3509+ protected_kw = ['y' , 'horizontalalignment' , 'ha' ]
3510+ if {* kwargs } & {* protected_kw }:
3511+ if loc is not None :
3512+ raise TypeError (f"Specifying 'loc' is disallowed when any of "
3513+ f"its corresponding low level keyword "
3514+ f"arguments ({ protected_kw } ) are also "
3515+ f"supplied" )
3516+ loc = 'center'
3517+ else :
3518+ loc = (loc if loc is not None
3519+ else mpl .rcParams ['yaxis.labellocation' ])
3520+ cbook ._check_in_list (('bottom' , 'center' , 'top' ), loc = loc )
3521+ if loc == 'bottom' :
3522+ kwargs .update (y = 0 , horizontalalignment = 'left' )
3523+ elif loc == 'top' :
3524+ kwargs .update (y = 1 , horizontalalignment = 'right' )
3525+ return self .yaxis .set_label_text (ylabel , fontdict , ** kwargs )
3526+
34193527 def invert_yaxis (self ):
34203528 """
34213529 Invert the y-axis.
0 commit comments