Set Font Properties for Titles and Labels
In order to make the Plot more attractive use the fontdict parameter in xlabel(), ylabel(), and title() to apply the font properties.
Python
# Adding font properties to labels and titles import matplotlib import matplotlib.pyplot as plt import numpy as np # Number of Children x = np.array([ 0 , 1 , 2 , 3 ]) # Number of Families y = np.array([ 3 , 8 , 1 , 10 ]) # label including this form1 will have these properties form1 = { 'family' : 'serif' , 'color' : 'blue' , 'size' : 20 } # label including this form2 will have these properties form2 = { 'family' : 'serif' , 'color' : 'darkred' , 'size' : 15 } plt.plot(x, y) plt.xlabel( "Number of Childrens" , fontdict = form1) plt.ylabel( "Number of Families" , fontdict = form1) plt.title( "Survey Of Colony" , fontdict = form2) plt.show() |
Output:
How to Add Labels in a Plot using Python?
Prerequisites: Python Matplotlib
In this article, we will discuss adding labels to the plot using Matplotlib in Python. But first, understand what are labels in a plot. The heading or sub-heading written at the vertical axis (say Y-axis) and the horizontal axis(say X-axis) improves the quality of understanding of plotted stats.
Example: Let’s create a simple plot
Python
# python program to plot graph without labels import matplotlib import matplotlib.pyplot as plt import numpy as np # it will take x coordinates by default # starting from 0,1,2,3,4... y = np.array([ 3 , 8 , 1 , 10 ]) plt.plot(y) plt.show() |
Output: