Brief introduction
As, pyplot module is used to draw the two-dimensional map, matplotlib mplot3d module using three-dimensional graphics rendering, is present in the module mplot3d
mpl_toolkits.mplot3d.axes3d
mpl_toolkits.mplot3d.axis3d
mpl_toolkits.mplot3d.art3d
mpl_toolkits.mplot3d.proj3d
Four categories, including the most commonly used is mpl_toolkits.mplot3d.axes3d
Before doing what you need to understand three-dimensional view of that? D is based on a two-dimensional plane, the addition of a direction vector. Can be understood: the two-dimensional plane with x, y represent two vectors, the three-dimensional space with x, y, Z represents three vectors. Look at two simple test cases, create two-dimensional images and three-dimensional images with matplotlib respectively:
import numpy as np
import matplotlib.pyplot as plt
x=np.array([1,2])
y=np.array([1,2])
plt.plot (x, y) # where incoming values x, y of
plt.show()
>>
from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.gca(projection='3d') x=np.array([1,2]) y=np.array([1,2]) z=np.array([1,2]) ax.plot(x, y, z, label='parametric curve') #这里传入x, y, z的值 ax.legend() plt.show()
>>
In the second instance on the basis of a first instance, the addition of a vector z = np.array ([1,2]), to achieve three-dimensional effect. My understanding is that when z = np.array ([0,0]) when it is a two-dimensional plane, but we used a three-dimensional "drawing board" ax
The following is a translation from the official reference documentation matplotlib over content
The official document: https: //matplotlib.org/tutorials/toolkits/mplot3d.html
Getting Started
Creating a Axes3D objects created with other axes similar method, using using the projection = '3d' keyword to create a matplotlib.figure.Figure object and assigned to a new Axes3D types of axes
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111, projection='3d')
In the new version 1.0.0, which is the preferred method to create a type of axes of Axes3D
Line plots
Axes3D.plot (self, xs, ys, * args, zdir = 'z', ** kwargs) may draw two or three dimensional data
parameter:
xs: one-dimensional array, an x-coordinate of the vertex
ys: one-dimensional array, y coordinates of vertices
zs: scalar or one-dimensional array. Z vertex coordinates, either One for All Points or One for each Point.
Zdir: { 'X', 'Y', 'z'} when drawing a two-dimensional image, using z ( 'x', 'y ' or 'z')
# This import registers the 3D projection, but is otherwise unused. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import import numpy as np import matplotlib.pyplot as plt plt.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d') # Prepare arrays x, y, z theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) z = np.linspace(-2, 2, 100) r = z**2 + 1 x = r * np.sin(theta) y = r * np.cos(theta) ax.plot(x, y, z, label='parametric curve') ax.legend() plt.show()
>>