9 a] Develop a code for labels titles in matplotlib.
Labels
Matplotlib provides a few label functions that we can use for setting labels to the x- and y-axes. The plt.xlabel() and plt.ylabel() functions are used to set the label for the current axes. The set_xlabel() and set_ylabel() functions are used to set the label for specified axes.
Example:
ax.set_xlabel('X Label') ax.set_ylabel('Y Label')
You should (always) add labels to make a visualization more self-explanatory. The same is valid for titles, which will be discussed now.
Titles
A title describes a particular chart/graph. The titles are placed above the axes in the center, left edge, or right edge. There are two options for titles – you can either set the Figure title or the title of an Axes. The suptitle() function sets the title for the current and specified Figure. The title() function helps in setting the title for the current and specified axes.
Example:
fig = plt.figure() fig.suptitle('Suptitle', fontsize=10, fontweight='bold')
This creates a bold Figure title with a text subtitle and a font size of 10:
plt.title('Title', fontsize=16)
The plt.title function will add a title to the Figure with text as Title and font size of 16 in this case.