DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

How to Create 3D Subplots in Matplotlib (Python)

Create multiple 3D panels in Matplotlib by adding axes with projection='3d' and plotting through each returned axes object.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Create each 3D panel with projection='3d', then plot through the axes object returned by Matplotlib. Give each panel a different subplot index to place several 3D plots in one figure.

Create a row of two 3D subplots

Use Figure.add_subplot(rows, columns, index, projection='3d') for each 3D axes. The first two arguments define the grid; the last selects the panel’s position, counting from 1.

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(10, 5))
ax1 = fig.add_subplot(1, 2, 1, projection='3d')
ax2 = fig.add_subplot(1, 2, 2, projection='3d')

ax1.scatter([0, 1, 2], [0, 1, 0], [0, 1, 2])
ax2.plot([0, 1, 2], [0, 1, 1], [0, 1, 2])

plt.show()

This creates one row and two columns: a 3D scatter plot on the left and a 3D line plot on the right. The official Matplotlib example of 3D plots as subplots uses the same pattern, with a surface and wireframe side by side.

Choose plot methods for each axes

Call plotting methods on the returned axes rather than relying on pyplot functions. Matplotlib’s mplot3d API documentation notes that pyplot functions have strictly 2D signatures and cannot handle the extra information required for 3D plots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • ax.scatter(x, y, z) displays 3D point data.
  • ax.plot(x, y, z) displays a line or trajectory.
  • ax.plot_surface(X, Y, Z) is suitable for gridded height data.
  • ax.plot_wireframe(X, Y, Z) shows the mesh structure of a surface.

For a surface, the official gallery example also demonstrates setting a z-axis limit and attaching a colorbar to the surface artist. If neighboring panels use color to represent values, choose color scales deliberately: matching scales makes colors comparable, while independent scales can emphasize each panel’s own range.

Arrange other grids and mix 2D with 3D

For a different layout, change the grid dimensions and use a distinct index for each axes. For example, a 2-by-2 grid uses fig.add_subplot(2, 2, 1, projection='3d') through fig.add_subplot(2, 2, 4, projection='3d') to fill all four positions with 3D plots.

A figure can also combine 2D and 3D panels. Add an ordinary 2D axes without a projection argument, and specify projection='3d' only for the 3D axes. Matplotlib’s mixed 2D and 3D subplot example places a 2D subplot above a 3D surface plot.

Size, labels, and interaction

Set the figure dimensions to suit the number and shape of panels. The figsize=(10, 5) value in the example makes a wide two-panel layout; it is a presentation choice, not an API requirement. Add axis labels and limits to the relevant axes, and attach a colorbar to the artist it describes.

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.

Some interactive Matplotlib backends support rotating and zooming a 3D scene with mouse gestures. The available interaction depends on the backend, as described in the mplot3d documentation.

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

Do you need to import mplot3d?

For current Matplotlib, you generally do not need to import mpl_toolkits.mplot3d just to make the '3d' projection available to add_subplot. The stable 3D plotting tutorial says that explicit import stopped being necessary in Matplotlib 3.2.0. Older examples may include it for that reason.

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.

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
PC Slower Than It Used to Be?Free scan - under a minute
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.