subplots()

noun

say it: “SUB-plots” /ˈsʌbˌplɑts/

A matplotlib function that makes a figure and one chart, or a grid of charts, in one step.

What does subplots() do in matplotlib?

subplots() (plt.subplots) makes a Figure and its Axes in one call. With no arguments it gives one chart; with a number of rows and columns it gives a grid of charts on one page, each picked as axs[row, column], counting from 0.

import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2, figsize=(10, 8), layout="constrained")
axs[0, 0].plot(monthly.index, monthly["tons_recycled"])        # top left
axs[1, 1].barh(by_neighborhood.index, by_neighborhood.values)  # bottom right

In a sentence

  • “He called subplots() with sharey=True so both charts used one scale.”
  • “subplots() gave her a 2 by 2 grid for the summary page.”

Level: Journeyman · More Python terms at this level

Updated