Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements.
The text() method figure module of matplotlib library is used to Add text to figure.
Syntax: text(self, x, y, s, fontdict=None, withdash=, **kwargs)
Parameters: This method accept the following parameters that are discussed below:
- x: This parameter is the x position to place the text.
- y: This parameter is the y position to place the text.
- s: This parameter is the text string.
- fontdict : This parameter is the dictionary to override the default text properties.
- withdash : This parameter is used to create a TextWithDash instance instead of a Text instance.
Returns: This method returns the Text.
Below examples illustrate the matplotlib.figure.Figure.text() function in matplotlib.figure:
Example 1:
#Implementation of matplotlib function import matplotlib.pyplot as plt fig, ax = plt.subplots() fig.text( 0.28 , 0.5 , 'Lazyroar' , style = 'italic' , fontsize = 30 , color = "green" ) ax. set (xlim = ( 0 , 8 ), ylim = ( 0 , 8 )) fig.suptitle( """matplotlib.figure.Figure.text() function Example\n\n""" ,fontweight = "bold") fig.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' ) fig.text( 0.3 , 0.7 , 'Lazyroar' , style = 'italic' , fontsize = 30 , bbox = { 'facecolor' : 'green' , 'alpha' : 0.6 , 'pad' : 10 }) fig.text( 0.35 , 0.6 , 'Python matplotlib Module' , fontsize = 15 ) fig.text( 0.35 , 0.3 , 'Figure Class - Text Function' ) fig.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 )) fig.suptitle( """matplotlib.figure.Figure.text() function Example\n\n""" , fontweight = "bold") fig.show() |
Output: