Python plot_surface (Axes3D) Method: drawing 3D graphics

3D contour map data required is substantially the same pattern: X, Y coordinate data decision point, Z-axis data decided X, Y coordinates of the point corresponding to the height. And a contour map used to represent the contour lines of different heights, 3D graphics to be represented in the form of a more intuitive level.

In order to draw 3D graphics, you need to call Axes3D object plot_surface () method to complete.

The following will use the previous contour plot of the same data to the 3D graphics rendering, you will see that this time the program will display a more intuitive form height.

Import matplotlib.pyplot AS PLT
 Import numpy AS NP
 from mpl_toolkits.mplot3d Import Axes3D 
Fig = plt.figure (figsize = (12 is,. 8 )) 
AX = Axes3D (Fig) 
Delta = 0.125
 # generating a representative list of the X-axis data 
x = np .arange (-3.0, 3.0 , Delta)
 # generates list data representative of the Y-axis 
Y np.arange = (-2.0, 2.0 , Delta)
 # of x, y grid of data performed 
X-, Y = np.meshgrid (X , Y) 
Zl = np.exp (the -X-2 ** - the Y ** 2 ) 
Z2 of = np.exp (- (X--. 1) ** 2 - (the Y -. 1) ** 2 )
 # calculation data Z axis (height data)
= The Z (Zl - Z2 of) * 2 # drawing 3D graphics ax.plot_surface (X-, the Y, the Z, 
    rstride =. 1,   # span rstride (row) of the specified row 
    cstride =. 1,   # cstride (column) designated column span 
    cmap plt.get_cmap = ( ' Rainbow ' ))   # set the color mapping 
# set the Z-axis range 
ax.set_zlim (-2, 2 )
 # set title 
plt.title ( " 3D FIG. " ) 
plt.savefig ( " D: / Test. PNG " ) 
plt.show ()

 

The above program is started and before a procedure to prepare the same data, but the program is set to 0.125 delta, to avoid generating too much data points (when drawing 3D graphics, a large computational overhead, if too many data points, Matplotlib It will be very slow).

Line 20 calls the program code object Axes3D plot_surface () method for drawing 3D graphics, wherein X, Y parameters responsible for determining the coordinates of points, Z parameters determine height data X, Y coordinates of the point.

Run the above procedures, can be seen in FIG. 3D pattern shown in FIG. 1.

Guess you like

Origin www.cnblogs.com/gisoracle/p/12025156.html