close

How to plot multiple pandas columns

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to plot multiple pandas columns in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to plot multiple pandas columns?

  1. How to plot multiple pandas columns?

    Pandas.DataFrame.plot() per default uses index for plotting X axis, all other numeric columns will be used as Y values.

  2. plot multiple pandas columns

    Pandas.DataFrame.plot() per default uses index for plotting X axis, all other numeric columns will be used as Y values.

Method 1

Several column names may be provided to the y argument of the pandas plotting function. Those should be specified in a list, as follows.

df.plot(x="year", y=["action", "comedy"])

Complete example:

import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame({"year": [1914,1915,1916,1919,1920],
                   "action" : [2.6,3.4,3.25,2.8,1.75],
                   "comedy" : [2.5,2.9,3.0,3.3,3.4] })
df.plot(x="year", y=["action", "comedy"])
plt.show()
enter image description here

Method 2

Pandas.DataFrame.plot() per default uses index for plotting X axis, all other numeric columns will be used as Y values.

So setting year column as index will do the trick:

total_year.set_index('year').plot(figsize=(10,5), grid=True)

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read