Plot guides › Chart types

Dual-axis chart (two y-axes)

A dual-axis chart shares the x-axis but gives each series its own y-axis, for two quantities in different units such as temperature and rainfall.

Example dual-axis chart (two y-axes) made with matplotlib
Rendered from the code below, with example data.

When to use it

Watch out: The scales are arbitrary, so any apparent crossing or correlation can be faked by rescaling. Consider two stacked panels.

Ask for it in pltchat

Upload your file and type something like:

"temperature as a line on the left axis, rainfall as bars on the right axis"

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 matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
temp = [3, 4, 8, 12, 16, 20, 22, 21, 17, 12, 7, 4]
rain = [70, 55, 60, 50, 65, 70, 80, 85, 60, 75, 85, 80]

fig, ax1 = plt.subplots(figsize=(6.4, 4))
ax2 = ax1.twinx()
ax2.bar(months, rain, color="C0", alpha=0.35)
ax1.plot(months, temp, color="C3", marker="o")
ax1.set_zorder(ax2.get_zorder() + 1)
ax1.patch.set_visible(False)
ax1.set_ylabel("Temperature (°C)", color="C3")
ax2.set_ylabel("Rainfall (mm)", color="C0")
ax1.tick_params(axis="y", colors="C3")
ax2.tick_params(axis="y", colors="C0")
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