In [1]:
import pandas as pd

Customizing graphs using Labels, Titles, Legend

1. Labels

In [27]:
plt.plot(data.stroke,data.price,'ro')
## Setting labels to be displayed
plt.xlabel('Stroke size')
plt.ylabel('Price of car')
Out[27]:
Text(0,0.5,'Price of car')

How to change the figure size?

In [28]:
## setting the figure size = (8,8)
plt.figure(figsize=(8,8))
plt.plot(data.stroke,data.price,'ro')
## Setting labels to be displayed
plt.xlabel('Stroke size')
plt.ylabel('Price of car')
Out[28]:
Text(0,0.5,'Price of car')

2. Title

In [29]:
plt.plot(data.stroke,data.price,'ro')
## Setting labels to be displayed
plt.xlabel('Stroke size')
plt.ylabel('Price of car')
plt.title('Line plot for stroke vs Prices')
Out[29]:
Text(0.5,1,'Line plot for stroke vs Prices')

3. Legend

In [30]:
## Displaying two plots in a same graph ans set the labels, red color shows stroke and blue color shows bore value w.r.t prices
plt.plot(data.stroke,data.price,'ro',label='stroke')
plt.plot(data.bore,data.price,'bo',label='bore')
## Setting labels to be displayed
plt.xlabel('Stroke size')
plt.ylabel('Price of car')
## Setting the title
plt.title('Line plot for stroke and bore vs Prices')
## Using legend in the graph in order to display the label written in plot function.
plt.legend()
Out[30]:
<matplotlib.legend.Legend at 0x18703ce5080>