Generating 3D plots using the mplot3d toolkit.
.. currentmodule:: mpl_toolkits.mplot3d
Contents
An Axes3D object is created just like any other axes using the projection='3d' keyword. Create a new :class:`matplotlib.figure.Figure` and add a new axes to it of type :class:`~mpl_toolkits.mplot3d.Axes3D`:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d').. versionadded:: 1.0.0
This approach is the preferred method of creating a 3D axes.
Note
Prior to version 1.0.0, the method of creating a 3D axes was
different. For those using older versions of matplotlib, change
ax = fig.add_subplot(111, projection='3d')
to ax = Axes3D(fig).
See the :ref:`toolkit_mplot3d-faq` for more information about the mplot3d toolkit.
.. automethod:: Axes3D.plot
.. automethod:: Axes3D.scatter
.. automethod:: Axes3D.plot_wireframe
.. automethod:: Axes3D.plot_surface
.. automethod:: Axes3D.plot_trisurf
.. automethod:: Axes3D.contour
.. automethod:: Axes3D.contourf
.. versionadded:: 1.1.0
The feature demoed in the second contourf3d example was enabled as a
result of a bugfix for version 1.1.0.
.. automethod:: Axes3D.add_collection3d
.. automethod:: Axes3D.bar
.. automethod:: Axes3D.quiver
.. automethod:: Axes3D.text
Having multiple 3D plots in a single figure is the same as it is for 2D plots. Also, you can have both 2D and 3D plots in the same figure.
.. versionadded:: 1.0.0
Subplotting 3D plots was added in v1.0.0. Earlier version can not
do this.
Total running time of the script: ( 0 minutes 0.000 seconds)
.. rst-class:: sphx-glr-signature
`Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_











