Saturday, November 22, 2025
HomeLanguagesMatplotlib.axis.Axis.set_label_text() function in Python

Matplotlib.axis.Axis.set_label_text() function in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack.

Matplotlib.axis.Axis.set_label_text() Function

The Axis.set_label_text() function in axis module of matplotlib library is used to set the text value of the axis label.
 

Syntax: Axis.set_label_text(self, label, fontdict=None, **kwargs)

Parameters: This method accepts the following parameters. 

  • label : This parameter is the Text string.
  • fontdict : This parameter is the Text properties.

Return value: This method does not returns any value. 

Below examples illustrate the matplotlib.axis.Axis.set_label_text() function in matplotlib.axis:
 

Example 1:

Python3




# Implementation of matplotlib function 
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
   
fig, ax2 = plt.subplots(sharex = True)
fig.subplots_adjust(left=0.2, wspace=0.6)
box = dict(facecolor='green', pad=5, alpha=0.2)
   
ax2.plot(20*np.random.rand(10))
ax2.xaxis.set_label_text('X - Label', bbox=box)
ax2.set_xlim(0, 10)
   
fig.suptitle("Matplotlib.axis.Axis.set_label_text()\
Function Example", fontsize = 12, fontweight ='bold'
  
plt.show()


Output: 

Example 2:
 

Python3




# Implementation of matplotlib function 
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
    
fig, (ax1, ax2) = plt.subplots(2, 1, sharex = True)
fig.subplots_adjust(left=0.2, wspace=0.6)
box = dict(facecolor='green', pad=5, alpha=0.2)
    
np.random.seed(19680801)
ax1.plot(2*np.random.rand(10))
ax1.set_title('Label is not aligned')
ax1.yaxis.set_label_text('Default', bbox=box)
ax1.set_ylim(0, 20)
    
ax2.set_title('\nLabel is aligned')
ax2.plot(20*np.random.rand(10))
ax2.yaxis.set_label_text('Adjusted', bbox=box)
ax2.yaxis.set_label_position('right')
ax2.set_ylim(0, 20)
    
fig.suptitle("Matplotlib.axis.Axis.set_label_text()\
Function Example", fontsize = 12, fontweight ='bold'
  
plt.show()


Output: 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11929 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS