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.get_title() Function
The Axes.get_title() function in axes module of matplotlib library is used to Get an axes title.
Syntax: Axes.get_title(self, loc=ācenterā)
Parameters: This method accepts the following parameters.
- loc : This parameter is an optional parameter and it is used for Which title to get.
Return: This function return the title text string.
Below examples illustrate the matplotlib.axes.Axes.get_title() function in matplotlib.axes:
Example 1:
# Implementation of matplotlib function import os from matplotlib import font_manager as fm, rcParams import matplotlib.pyplot as plt Ā Ā Ā fig, ax = plt.subplots() Ā Ā Ā fpath = os.path.join(rcParams[ "datapath" ],Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā "fonts / ttf / cmr10.ttf" ) prop = fm.FontProperties(fname = fpath) fname = os.path.split(fpath)[ 1 ] ax.set_title( 'Title with special font: {}' . format (fname), Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fontproperties = prop, fontsize = 14 ) Ā Ā w = ax.get_title() ax.text( 0.2 , 0.6 , "Previously assigned title : \n\n" + str (w), Ā Ā Ā Ā Ā Ā Ā Ā fontsize = 14 ) ax.set_title("matplotlib.axes.Axes.get_title() \ function Example\n ", fontweight =" bold") plt.show() |
Output:
Example 2:
# Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt Ā Ā Ā x = np.arange( 0.1 , 5 , 0.1 ) y = np.exp( - x) Ā Ā Ā yerr = 0.1 + 0.1 * np.sqrt(x) Ā Ā Ā fig, (ax, ax1) = plt.subplots(nrows = 1 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ncols = 2 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā sharex = True ) Ā Ā ax.errorbar(x, y, yerr = yerr, color = "green" ) ax.set_title( 'Title of Axes 1' , fontweight = "bold" ) Ā Ā Ā ax1.errorbar(x, y, yerr = yerr, errorevery = 5 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā color = "green" ) ax1.set_title( 'Title of Axes 2' , fontweight = "bold" ) Ā Ā w = ax.get_title() ww = ax1.get_title() ax.set_title("") ax1.set_title("") Ā Ā ax.set_xlabel(w) ax1.set_xlabel(ww) Ā Ā fig.suptitle("Previously assigned title of each Axes is \ Ā used at labels\n ", fontweight =" bold") plt.show() |
Output: