Amazing technological breakthrough possible @S-Logix

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • +91- 81240 01111

Social List

How to implement legends, titles, and labels with Matplotlib in python?


To differentiate two different curves
using matplotlib legends, titles and labels using python.


   Import matplotlib package and sub packages also.

   Load the data set.

   Use plot function to differentiate two curves.

   Pass the corresponding variable to the plot function.

Sample Code

#import libraries
import matplotlib.pyplot as plt
import pandas as pd

#sample data

#create data frame
x = (df[‘salary’])
y = (df[‘bonus’])

x2 = (df[‘rating’])
y2 = (df[‘age’])

#call the plot functions
plt.plot(x, y, label=’First Line’,color=’r’)

#second curve
plt.plot(x2, y2, label=’Second Line’,color=’g’)

#define the labels and title
plt.xlabel(‘Salary and rating’)
plt.ylabel(‘age and bonus’)
plt.title(‘Legends, Tables and Titles’)

#call the legend function

implement legends, titles, and labels with Matplotlib in python