- 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
Plot a Line Graph for Pandas Dataframe with Matplotlib?
We will plot a line grapg for Pandas DataFrame using the plot(). At first, import the required libraries −
import pandas as pd import matplotlib.pyplot as plt
Create a DataFrame −
dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'],"Reg_Price": [2000, 2500, 2800, 3000, 3200, 3500],"Units": [100, 120, 150, 170, 180, 200] } )
Plot a line graph with both the columns −
plt.plot(dataFrame["Reg_Price"], dataFrame["Units"])
Example
Following is the code −
import pandas as pd import matplotlib.pyplot as plt # creating a DataFrame with 2 columns dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'],"Reg_Price": [2000, 2500, 2800, 3000, 3200, 3500],"Units": [100, 120, 150, 170, 180, 200] } ) # plot a line graph plt.plot(dataFrame["Reg_Price"], dataFrame["Units"]) plt.show()
Output
This will produce the following output −
- Related Articles
- Python - Plot a Pandas DataFrame in a Line Graph
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Python - Plot a Pie Chart for Pandas Dataframe with Matplotlib?
- How to plot a Pandas Dataframe with Matplotlib?
- How to plot a Pandas multi-index dataFrame with all xticks (Matplotlib)?
- Annotating points from a Pandas Dataframe in Matplotlib plot
- Frequency plot in Python/Pandas DataFrame using Matplotlib
- Python - How to plot a Pandas DataFrame in a Bar Graph
- How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?
- How to plot certain rows of a Pandas dataframe using Matplotlib?
- Python - Draw a Scatter Plot for a Pandas DataFrame
- How to plot an area in a Pandas dataframe in Matplotlib Python?
- How to change the DPI of a Pandas Dataframe Plot in Matplotlib?
- How to plot a bar graph in Matplotlib from a Pandas series?
- How to plot a line graph from histogram data in Matplotlib?

Advertisements