matplotlib painting 3d map

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


= Fig plt.figure () AX = Axes3D (Fig) X = np.arange (-4,. 4, 0.25 ) Print (X) Y = np.arange (-4,. 4, 0.25 ) X, Y = np.meshgrid (X, Y) # np.sqrt (X): calculates the square root of each element array R & lt np.sqrt = (X ** 2 + Y ** 2 ) # height value Z = np.sin (R & lt) ax.plot_surface ( X, Y, Z, rstride =. 1, cstride =. 1, CMap = ' Rainbow ' ) # zdir that represents the axis projection ax.contourf (X, Y, Z, zdir = ' Z ' , offset = -2, CMap =' Rainbow ' ) # set the height of the contour line ax.set_zlim (-2, 2 ) plt.savefig ( ' ./image_dir/3d.png ' ) plt.show ()

Guess you like

Origin www.cnblogs.com/heguihui/p/12183238.html