GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Plot types
  • User guide
  • Tutorials
  • Examples
  • Reference
  • Contribute
  • Releases
  • Gitter
  • Discourse
  • GitHub
  • Lines, bars and markers
  • Line plot
  • Linestyles
  • Dashed line style configuration

This view

  • Original page
  • New address

GeezerVison is showing matplotlib.org — 3D plots as subplots — Matplotlib 3.11.2 documentation

Note

Go to the end to download the full example code.

3D plots as subplots#

Demonstrate including 3D plots as subplots.

import matplotlib.pyplot as plt
import numpy as np

from mpl_toolkits.mplot3d.axes3d import get_test_data

# set up a figure twice as wide as it is tall
fig = plt.figure(figsize=plt.figaspect(0.5))

# =============
# First subplot
# =============
# set up the Axes for the first plot
ax = fig.add_subplot(1, 2, 1, projection='3d')

# plot a 3D surface like in the example mplot3d/surface3d_demo
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap="coolwarm",
                       linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
fig.colorbar(surf, shrink=0.5, aspect=10)

# ==============
# Second subplot
# ==============
# set up the Axes for the second plot
ax = fig.add_subplot(1, 2, 2, projection='3d')

# plot a 3D wireframe like in the example mplot3d/wire3d_demo
X, Y, Z = get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()
subplot3d

Tags: plot-type: 3D component: subplot level: advanced

Download Jupyter notebook: subplot3d.ipynb

Download Python source code: subplot3d.py

Download zipped: subplot3d.zip

Gallery generated by Sphinx-Gallery

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.