在数据可视化的世界中,3D曲面图是一种强大的工具,能够将复杂的数据模式以清晰直观的方式展现出来。Python提供了多种库和工具,使得创建和定制3D曲面图变得简单而令人兴奋。本文将介绍如何使用Python中的Matplotlib和mpl_toolkits.mplot3d库绘制令人印象深刻的3D曲面图。 准备工作 首先,确保你的Python环境中安装了Matplotlib...
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选项:输出图像是一...
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # 定义三个变量的范围 x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) z = np.linspace(-5, 5, 100) # 使用 meshgrid 生成三维网格点 X, Y, Z = np.meshgrid(x, y, z) # 定...
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 ...
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 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...
from mpl_toolkits.mplot3dimport Axes3D x= numpy.linspace(-2,2,10) y= numpy.linspace(-2,2,10) xx, yy= numpy.meshgrid(x, y) z= xx** 2 - yy** 2 fig= plt.figure(figsize=(12,7)) ax1= plt.axes(projection='3d')# 创建三维坐标轴 ...
1importnumpyasnp2frommatplotlibimportpyplotasplt3frommpl_toolkits.mplot3dimportAxes3D4x=np.array([0,1,2])5y=np.array([0,1])6X,Y=np.meshgrid(x,y)#X,Y扩展成了矩阵,7print(X)8print(Y)9theta0,theta1,theta2=2,3,410ax=Axes3D(plt.figure())#用来画三维图11Z=theta0+theta1*X+theta2*...
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 Axes')plt.show()#---# END OF FILE : TEST2.PY#*** ▲ 3D 绘制...