Figure-level legend

fig.legend() draws one legend for the whole grid instead of repeating the same entries in every panel – labels are de-duplicated across axes. The "lower center" placement (default) reserves a band at that edge and shrinks the grid to fit, so it never lands on a plot.

plot 08 figure legend

Live figure — pick a tool, then zoom, pan, point-pick or annotate. Nothing is active until a tool is selected.

View this figure’s Vega export ↗ — the raw JSON spec, rendered live by a real Vega engine.

View this figure’s Vega-Lite export ↗ — the raw JSON spec(s), rendered live by a real Vega-Lite engine.

import numpy as np
import plotpress

x = np.linspace(0, 10, 200)

fig, axes = plotpress.subplots(1, 2, figsize=(7, 3.2))
for ax in axes:
    ax.plot(x, np.sin(x), color="#1f77b4", label="sin")
    ax.plot(x, np.cos(x), color="#d62728", linestyle="--", label="cos")
fig.legend(loc="lower center", ncol=2)
fig.tight_layout()

Total running time of the script: (0 minutes 0.077 seconds)

Gallery generated by Sphinx-Gallery