Wednesday, December 25, 2024
Google search engine
HomeLanguagesMatplotlib.axes.Axes.text() in Python

Matplotlib.axes.Axes.text() in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.text() Function

The Axes.text() function in axes module of matplotlib library is also used to add the text s to the axes at location x, y in data coordinates.

Syntax:

Axes.text(self, x, y, s, fontdict=None, withdash=, **kwargs)

Parameters: This method accept the following parameters that are described below:

  • s: This parameter is the text to be add.
  • xy: This parameter is the point (x, y) where text is to be placed.
  • fontdict: This parameter is an optional parameter and a dictionary to override the default text properties.
  • withdash: This parameter is also an optional parameter and creates a TextWithDash instance instead of a Text instance.

Returns: This method returns the text which is a created text instance..

Below examples illustrate the matplotlib.axes.Axes.text() function in matplotlib.axes:

Example-1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
  
fig, ax = plt.subplots()
ax.text(3, 4, 'Lazyroar', style ='italic',
        fontsize = 30, color ="green")
  
ax.set(xlim =(0, 8), ylim =(0, 8))
ax.set_title('matplotlib.axes.Axes.text() Example',
             fontsize = 14, fontweight ='bold')
  
plt.show()


Output:

Example-2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
  
fig, ax = plt.subplots()
ax.set_xlabel('xlabel')
ax.set_ylabel('ylabel')
  
ax.text(3, 8, 'Lazyroar',
        style ='italic',
        fontsize = 30,
        bbox ={'facecolor':'green',
               'alpha':0.6, 'pad':20})
  
ax.text(3.5, 6, 'Python matplotlib Module',
        fontsize = 15)
  
ax.text(3.5, 3, 'Axes Class - Text Function')
  
ax.text(0, 0, 'by-Shubham Singh',
        verticalalignment ='bottom',
        horizontalalignment ='left',
        transform = ax.transAxes,
        color ='green', fontsize = 5)
  
  
  
ax.set(xlim =(0, 10), ylim =(0, 10))
ax.set_title('matplotlib.axes.Axes.text() Example',
              fontsize = 14, fontweight ='bold')
plt.show()


Output:

RELATED ARTICLES

Most Popular

Recent Comments