- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?
To plot multiple Pandas columns on the Y-axis of a line graph, we can set the index using set_index() method.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create a dataframe with Category 1, Category 2, and Category 3 columns.
- Use set_index() method to set the DataFrame index using existing columns.
- To display the figure, use show() method.
Example
import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'Category 1': [2, 4, 5, 1, 0, 3], 'Category 2': [6, 3, 1, 4, 5, 2], 'Category 3': [2, 4, 1, 3, 6, 0]}) df.set_index('Category 1').plot() plt.show()
Output
- Related Articles
- Plot multiple columns of Pandas dataframe on the bar chart in Matplotlib
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- How to plot two Pandas time series on the same plot with legends and secondary Y-axis in Matplotlib?
- Plot multiple boxplots in one graph in Pandas or Matplotlib
- How to show a bar and line graph on the same plot in Matplotlib?
- How to plot multiple lines on the same Y-axis in Python Plotly?
- How to plot a line graph from histogram data in Matplotlib?
- How to plot a bar graph in Matplotlib from a Pandas series?
- Plot multiple columns of Pandas DataFrame using Seaborn
- Python - Plot a Pandas DataFrame in a Line Graph
- How to plot a rectangle on a datetime axis using Matplotlib?
- Python Pandas - Plot multiple data columns in a DataFrame?
- Setting Y-axis in Matplotlib using Pandas
- Show the origin axis (x,y) in Matplotlib plot
- Python - Create a Time Series Plot with multiple columns using Line Plot

Advertisements