Note
Click here to download the full example code
Generating 3D plots using the mplot3d toolkit.
Contents
An Axes3D object is created just like any other axes using
the projection='3d' keyword.
Create a new matplotlib.figure.Figure
and
add a new axes to it of type Axes3D
:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
New in version 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 mplot3d FAQ for more information about the mplot3d toolkit.
Axes3D.
plot
(self, xs, ys, *args, zdir='z', **kwargs)[source]¶Plot 2D or 3D data.
Parameters: 


Axes3D.
scatter
(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True, *args, **kwargs)[source]¶Create a scatter plot.
Parameters: 


Returns: 

Axes3D.
plot_wireframe
(self, X, Y, Z, *args, **kwargs)[source]¶Plot a 3D wireframe.
Note
The rcount and ccount kwargs, which both default to 50, determine the maximum number of samples used in each direction. If the input data is larger, it will be downsampled (by slicing) to these numbers of points.
Parameters: 


Axes3D.
plot_surface
(self, X, Y, Z, *args, norm=None, vmin=None, vmax=None, lightsource=None, **kwargs)[source]¶Create a surface plot.
By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the cmap argument.
Note
The rcount and ccount kwargs, which both default to 50, determine the maximum number of samples used in each direction. If the input data is larger, it will be downsampled (by slicing) to these numbers of points.
Parameters: 


Axes3D.
plot_trisurf
(self, *args, color=None, norm=None, vmin=None, vmax=None, lightsource=None, **kwargs)[source]¶Plot a triangulated surface.
The (optional) triangulation can be specified in one of two ways; either:
plot_trisurf(triangulation, ...)
where triangulation is a Triangulation
object, or:
plot_trisurf(X, Y, ...)
plot_trisurf(X, Y, triangles, ...)
plot_trisurf(X, Y, triangles=triangles, ...)
in which case a Triangulation object will be created. See
Triangulation
for a explanation of
these possibilities.
The remaining arguments are:
plot_trisurf(..., Z)
where Z is the array of values to contour, one per point in the triangulation.
Parameters: 


Examples
(Source code, png, pdf)
(Source code, png, pdf)
New in version 1.2.0: This plotting function was added for the v1.2.0 release.
Axes3D.
contour
(self, X, Y, Z, *args, extend3d=False, stride=5, zdir='z', offset=None, **kwargs)[source]¶Create a 3D contour plot.
Parameters: 


Returns: 

Axes3D.
contourf
(self, X, Y, Z, *args, zdir='z', offset=None, **kwargs)[source]¶Create a 3D filled contour plot.
Parameters: 


Returns: 

Notes
New in version 1.1.0: The zdir and offset parameters.
New in version 1.1.0: The feature demoed in the second contourf3d example was enabled as a result of a bugfix for version 1.1.0.
Axes3D.
bar
(self, left, height, zs=0, zdir='z', *args, **kwargs)[source]¶Add 2D bar(s).
Parameters: 


Returns: 

Axes3D.
quiver
(X, Y, Z, U, V, W, /, length=1, arrow_length_ratio=.3, pivot='tail', normalize=False, **kwargs)[source]¶Plot a 3D field of arrows.
The arguments could be arraylike or scalars, so long as they they can be broadcast together. The arguments can also be masked arrays. If an element in any of argument is masked, then that corresponding quiver element will not be plotted.
Parameters: 


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.
New in version 1.0.0: Subplotting 3D plots was added in v1.0.0. Earlier version can not do this.
Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by SphinxGallery