Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Make a Multiline Plot from a CSV File in Matplotlib

Load CSV columns with pandas and plot multiple labeled lines on the same Matplotlib axes, with checks for numeric values and dates.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Load the CSV into a pandas DataFrame, select one column for the x-axis and one or more columns for the y-axis, then plot each y column on the same Matplotlib axes. Check that numeric columns were parsed as numbers and dates as datetimes before plotting; otherwise, the chart may not represent the data as intended.

Load and check the CSV

Use pandas.read_csv() to load the file. The example below assumes the CSV has headers named date, sales, and returns; replace them with the headers in your file.

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("data.csv", parse_dates=["date"])

fig, ax = plt.subplots()
ax.plot(df["date"], df["sales"], label="Sales")
ax.plot(df["date"], df["returns"], label="Returns")
ax.set_xlabel("Date")
ax.set_ylabel("Value")
ax.legend()
fig.tight_layout()
plt.show()

pandas.read_csv documentation covers parser options such as separators, headers, explicit data types, missing values, and date parsing. By default, the function expects comma-separated data and infers headers. If your file uses another delimiter or has no header row, set the appropriate arguments rather than relying on those defaults.

Verify the columns and types

Before plotting, confirm that the column names match the CSV and that the values have the intended types. A numeric-looking column imported as text may be plotted as categories. Matplotlib treats string x values categorically, which can produce a separate tick for every distinct string. Convert values intended as numbers to numeric data before charting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For dates, parse the date column during CSV loading, as in parse_dates=["date"]. Matplotlib’s date converter supports datetime values and provides date-appropriate axis locators and formatters. See the Matplotlib units guide for details on date and string handling.

Plot multiple series on one set of axes

Each call to ax.plot() adds a line to the same axes. Pass the shared x column first and a y column second, then give each series a descriptive label. Calling ax.legend() displays those labels so readers can tell the lines apart.

Use axis labels that describe the plotted quantities. If the lines represent values with different units or scales, a single y-axis may be misleading; this pattern puts every series on the same axes and does not normalize or rescale their values.

Choose a plotting form that fits the data

Repeated calls for independent styling

The example uses one ax.plot(x, y, label=...) call per series. This is usually the clearest approach when each line needs its own label, marker, color, or line style. Matplotlib also supports line styling through arguments such as color, marker, and linestyle.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Two-dimensional y data for shared x values

If several y series are arranged as columns in a two-dimensional array and all share the same x coordinates, Matplotlib can plot the columns as separate lines in one call. This is concise for uniformly structured data; repeated calls are easier to read when series need individual labels or styling.

Grouped x/y pairs

plot() also accepts grouped x/y pairs in one call. The available forms are documented in the Matplotlib plot reference. Pick the form that keeps the relationship between each x series and its y series clear.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use the axes interface for a reusable figure

The example uses Matplotlib’s object-oriented interface: fig, ax = plt.subplots() creates a figure and axes, and plotting and labeling are performed through ax. This makes it straightforward to work with a particular axes, especially as a figure grows more complex. The pyplot overview describes pyplot’s role and recommends the object-oriented interface for complex plots; pyplot remains suitable for simple scripts and interactive use.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.