在数据可视化的世界中,3D曲面图是一种强大的工具,能够将复杂的数据模式以清晰直观的方式展现出来。Python提供了多种库和工具,使得创建和定制3D曲面图变得简单而令人兴奋。本文将介绍如何使用Python中的Matplotlib和mpl_toolkits.mplot3d库绘制令人印象深刻的3D曲面图。 准备工作 首先,确保你的Python
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 ...
ax = fig.add_subplot(111, projection='3d')x = np.linspace(-5, 5, 100)y = np.linspace(-5, 5, 100)X, Y = np.meshgrid(x, y)Z = np.sin(np.sqrt(X**2 + Y**2))surf = ax.plot_surface(X, Y, Z, cmap='coolwarm')plt.show()A选项:输出图像是一个点图B选项:输出图像是一...
from mpl_toolkits.mplot3d import Axes3D importnumpyas np X = np.array([-1, 0, 1]) Y = np.array([-1, 0, 1]) X, Y = np.meshgrid(X, Y) Z = X + Y fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_wireframe(X, Y, Z, color='r') plt.show(...
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...
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) ...
x_grid, y_grid = np.meshgrid(x_grid, y_grid) z_grid = f(x_grid, y_grid) # 创建曲面图 fig = go.Figure(data=[go.Surface(z=z_grid, x=x_grid, y=y_grid)]) fig.update_layout(scene=dict(xaxis_title='X', yaxis_title='Y', zaxis_title='Z'), ...
)ax = Axes3D(fig)X = np.array([0,1,2])Y = np.array([4,5,6])X, Y = np.meshgrid...
y=np.linspace(-5,5,50)# y轴坐标X,Y=np.meshgrid(x,y)Z=np.sin(np.sqrt(X**2+Y**2))# z轴坐标,这里使用sin函数生成一个曲面 # 创建一个三维坐标系 fig=plt.figure()ax=fig.add_subplot(111,projection='3d')# 绘制线框图 ax.plot_wireframe(X,Y,Z)# 设置坐标轴标签 ...