在数据可视化的世界中,3D曲面图是一种强大的工具,能够将复杂的数据模式以清晰直观的方式展现出来。Python提供了多种库和工具,使得创建和定制3D曲面图变得简单而令人兴奋。本文将介绍如何使用Python中的Matplotlib和mpl_toolkits.mplot3d库绘制令人印象深刻的3D曲面图。 准备工作 首先,确保你的Python
mplot3d import Axes3D 4 x = np.array([0,1,2]) 5 y = np.array([0,1]) 6 X,Y = np.meshgrid(x,y)#X,Y扩展成了矩阵, 7 print(X) 8 print(Y) 9 theta0, theta1, theta2 = 2, 3, 4 10 ax = Axes3D(plt.figure())#用来画三维图 11 Z = theta0 + theta1*X + theta2*Y...
mplot3d import Axes3D 4 x = np.array([0,1,2]) 5 y = np.array([0,1]) 6 X,Y = np.meshgrid(x,y)#X,Y扩展成了矩阵, 7 print(X) 8 print(Y) 9 theta0, theta1, theta2 = 2, 3, 4 10 ax = Axes3D(plt.figure())#用来画三维图 11 Z = theta0 + theta1*X + theta2*Y...
1,2])Y = np.array([4,5,6])X, Y = np.meshgrid(X, Y) //形成二维的网格点Z = np.a...
mplot3d import axes3d ax = plt.axes(projection='3d') x = arange(-5, 5, 0.1) y = arange(-5, 5, 0.1)x,y = meshgrid(x, y) R = sqrt(x*2+y**2) z = sin(R) ax.plot_surface(x, y, z) ax.set_xlabel('X Axes') ax.set_ylabel('Y Axes') ax.set_zlabel('Z ...
X, Y = np.meshgrid(x, y) Z = np.sin(np.sqrt(X**2+ Y**2))# 创建一个 3D 图形对象fig = plt.figure() ax = fig.add_subplot(111, projection='3d')# 绘制曲面ax.plot_surface(X, Y, Z, cmap='viridis')# 设置坐标轴标签ax.set_xlabel('X Axis') ...
ax3 = plt.axes(projection='3d') #定义三维数据 xx = np.arange(-10,10,100) yy = np.arange(-10,10,100) X, Y = np.meshgrid(x, y) Z = np.sin(X)+np.cos(Y) #作图 ax3.plot_surface(X,Y,Z,cmap='rainbow') #ax3.contour(X,Y,Z, zdim='z',offset=-2,cmap='rainbow) #等高线...
接着使用meshgrid生成坐标矩阵。 根据X和Y,计算Z的值。 调用plot_surface绘制出Z的图像。 运行程序,可以得到二元函数z的图像。 使用网格数据,还可以绘制等高线图: 等高线图,同样可以用于展示损失函数。 例如,使用plt.contour,绘制z=x^2+y^2的三维等高线图像。 其中相同颜色的圆圈,代表了相同的高度z。 将坐标系修...
ax = Axes3D(fig) delta = 0.125 # 生成代表X轴数据的列表 x = np.arange(-4.0, 4.0, delta) # 生成代表Y轴数据的列表 y = np.arange(-3.0, 4.0, delta) #对x、y数据执行网格化 X, Y = np.meshgrid(x, y) Z1 = np.exp(-X\*\*2 - Y\*\*2) ...
mplot3d import axes3d ax = plt.axes(projection='3d') x = arange(-5, 5, 0.1) y = arange(-5, 5, 0.1) x,y = meshgrid(x, y) R = sqrt(x*2+y**2) z = sin(R) ax.plot_surface(x, y, z) ax.set_xlabel('X Axes') ax.set_ylabel('Y Axes') ax.set_zlabel('Z ...