.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/mplot3d/subplot3d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_mplot3d_subplot3d.py: ==================== 3D plots as subplots ==================== Demonstrate including 3D plots as subplots. .. GENERATED FROM PYTHON SOURCE LINES 8-46 .. image-sg:: /gallery/mplot3d/images/sphx_glr_subplot3d_001.png :alt: subplot3d :srcset: /gallery/mplot3d/images/sphx_glr_subplot3d_001.png, /gallery/mplot3d/images/sphx_glr_subplot3d_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from matplotlib import cm 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=cm.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() .. _sphx_glr_download_gallery_mplot3d_subplot3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: subplot3d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: subplot3d.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_