- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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
Make a multiline plot from .CSV file in matplotlib
To make a multiline plot from .CSV file in matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a list of columns to fetch the data from a .CSV file. Make sure the names match with the column names used in the .CSV file.
- Read the data from the .CSV file.
- Plot the lines using df.plot() method.
- To display the figure, use show() method.
import pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Make a list of columns columns = ['mpg', 'displ', 'hp', 'weight'] # Read a CSV file df = pd.read_csv("auto-mpg.csv", usecols=columns) # Plot the lines df.plot() plt.show()
It will produce the following output
- Related Articles
- Plot data from CSV file with Matplotlib
- Plot data from a .txt file using matplotlib
- How to make a rug plot in Matplotlib?
- How to make a mosaic plot in Matplotlib?
- How to plot CSV data using Matplotlib and Pandas in Python?
- Write data from/to a .csv file in java
- How to make a simple lollipop plot in Matplotlib?
- How to plot a wav file using Matplotlib?
- Python Pandas- Create multiple CSV files from existing CSV file
- How to make a broken horizontal bar plot in Matplotlib?
- Writing data from database to .csv file
- How to read data from .csv file in Java?
- How to make a quiver plot in polar coordinates using Matplotlib?
- Make 3D plot interactive in Jupyter Notebook (Python & Matplotlib)
- How to make a discrete colorbar for a scatter plot in matplotlib?