Skip to content

Latest commit

 

History

History
253 lines (166 loc) · 4.95 KB

File metadata and controls

253 lines (166 loc) · 4.95 KB

The mplot3d Toolkit

Generating 3D plots using the mplot3d toolkit.

.. currentmodule:: mpl_toolkits.mplot3d

Getting started

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.

Line plots

.. automethod:: Axes3D.plot
../../gallery/mplot3d/images/sphx_glr_lines3d_001.png

Lines3d

Scatter plots

.. automethod:: Axes3D.scatter
../../gallery/mplot3d/images/sphx_glr_scatter3d_001.png

Scatter3d

Wireframe plots

.. automethod:: Axes3D.plot_wireframe
../../gallery/mplot3d/images/sphx_glr_wire3d_001.png

Wire3d

Surface plots

.. automethod:: Axes3D.plot_surface
../../gallery/mplot3d/images/sphx_glr_surface3d_001.png

Surface3d

Surface3d 2

Surface3d 3

Tri-Surface plots

.. automethod:: Axes3D.plot_trisurf
../../gallery/mplot3d/images/sphx_glr_trisurf3d_001.png

Trisurf3d

Contour plots

.. automethod:: Axes3D.contour
../../gallery/mplot3d/images/sphx_glr_contour3d_001.png

Contour3d

Contour3d 2

Contour3d 3

Filled contour plots

.. automethod:: Axes3D.contourf
../../gallery/mplot3d/images/sphx_glr_contourf3d_001.png

Contourf3d

Contourf3d 2
.. 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.

Polygon plots

.. automethod:: Axes3D.add_collection3d
../../gallery/mplot3d/images/sphx_glr_polys3d_001.png

Polys3d

Bar plots

.. automethod:: Axes3D.bar
../../gallery/mplot3d/images/sphx_glr_bars3d_001.png

Bars3d

Quiver

.. automethod:: Axes3D.quiver
../../gallery/mplot3d/images/sphx_glr_quiver3d_001.png

Quiver3d

2D plots in 3D

../../gallery/mplot3d/images/sphx_glr_2dcollections3d_001.png

2dcollections3d

Text

.. automethod:: Axes3D.text
../../gallery/mplot3d/images/sphx_glr_text3d_001.png

Text3d

Subplotting

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.
../../gallery/mplot3d/images/sphx_glr_subplot3d_001.png

Subplot3d

Mixed Subplots

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>`_