Open In App

How to Plot Multiple Series from a Pandas DataFrame?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to plot multiple series from a dataframe in pandas.

Series is the range of the data  that include integer points we cab plot in pandas dataframe by using plot() function

Syntax:

matplotlib.pyplot(dataframe['column_name'])

We can place n number of series and we have to call the show() function to display the plot

Example 1: Python code to create four dataframes and plot

Python3




#import matplotlib
import matplotlib.pyplot as plt
  
# import pandas module
import pandas as pd
  
# create a dataframe with four columns
data = pd.DataFrame({'data1': [1, 2, 3, 4, 21], 
                     'data2': [6, 7, 8, 9, 10], 
                     'data3': [11, 23, 21, 45, 67],
                     'data4': [22, 33, 45, 34, 56]})
  
# plot one by one
plt.plot(data['data1'])
plt.plot(data['data2'])
plt.plot(data['data3'])
plt.plot(data['data4'])
  
# set y label
plt.ylabel('Distance')
  
# set x label
plt.xlabel('Time')
  
# set title
plt.title('Travelling')
  
# display plot
plt.show()


Output:

Example 2: Plot with two columns from the dataframe

Python3




#import matplotlib
import matplotlib.pyplot as plt
  
# import pandas module
import pandas as pd
  
# create a dataframe with two columns
data = pd.DataFrame({'data1': [1, 2, 3, 4, 21],
                     'data2': [6, 7, 8, 9, 10]})
  
# plot one by one
plt.plot(data['data1'])
plt.plot(data['data2'])
  
# set y label
plt.ylabel('Distance')
  
# set x label
plt.xlabel('Time')
  
# set title
plt.title('Travelling')
  
# display plot
plt.show()


Output:



Last Updated : 28 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads