Python|Python 之 matplotlib (十一) 3D

代码:

import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3Dfig = plt.figure() ax = Axes3D(fig)# X,Y value X = np.arange(-4, 4, 0.25) Y = np.arange(-4, 4, 0.25) X, Y = np.meshgrid(X, Y) R = np.sqrt(X ** 2 + Y ** 2) # height value Z = np.sin(R)ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow')) ax.contourf(X, Y, Z, zdir='x', offset=-4, cmap='rainbow') ax.set_zlim(-2, 2) plt.show()

运行结果:
Python|Python 之 matplotlib (十一) 3D
文章图片


【Python|Python 之 matplotlib (十一) 3D】

    推荐阅读