How to Plot Multiple Series from a Pandas DataFrame?
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.pyplot as plt
import pandas as pd
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 ]})
plt.plot(data[ 'data1' ])
plt.plot(data[ 'data2' ])
plt.plot(data[ 'data3' ])
plt.plot(data[ 'data4' ])
plt.ylabel( 'Distance' )
plt.xlabel( 'Time' )
plt.title( 'Travelling' )
plt.show()
|
Output:
Example 2: Plot with two columns from the dataframe
Python3
import matplotlib.pyplot as plt
import pandas as pd
data = pd.DataFrame({ 'data1' : [ 1 , 2 , 3 , 4 , 21 ],
'data2' : [ 6 , 7 , 8 , 9 , 10 ]})
plt.plot(data[ 'data1' ])
plt.plot(data[ 'data2' ])
plt.ylabel( 'Distance' )
plt.xlabel( 'Time' )
plt.title( 'Travelling' )
plt.show()
|
Output:
Last Updated :
28 Nov, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...