Plot guides › Chart types

Line chart

A line chart connects measurements in order, usually over time, so the eye follows the trend, the turning points and the rate of change rather than individual values.

Example line chart made with matplotlib
Rendered from the code below, with example data.

When to use it

Watch out: Don't connect points from unordered categories (countries, products). Use a bar chart instead.

Ask for it in pltchat

Upload your file and type something like:

"line chart of revenue by month, markers on each point"

pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.

The matplotlib code

Self-contained with example data; swap in pd.read_csv(...) or pd.read_excel(...) for your own file.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Example data: replace with df = pd.read_csv("your_file.csv")
months = pd.date_range("2024-01-01", periods=12, freq="MS")
rng = np.random.default_rng(0)
df = pd.DataFrame({"month": months,
                   "revenue": 40 + np.cumsum(rng.normal(2, 3, 12))})

fig, ax = plt.subplots(figsize=(6.4, 4))
ax.plot(df["month"], df["revenue"], marker="o")
ax.set_xlabel("Month")
ax.set_ylabel("Revenue (k$)")
ax.set_title("Monthly revenue")
ax.grid(alpha=0.3)
fig.autofmt_xdate()
plt.tight_layout()
plt.show()

Make this with your data

Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.

Related plots