今晚开始接触 Matplotlib 的 3D 绘图函数 plot_surface,真的非常强大,图片质量可以达到出版级别,而且 3D 图像可以旋转 ,可以从不同角度来看某个 3D 立体图,但是我发现各大中文开源社区有关 3D 绘图的代码都是千篇一律的,现除了看源码说明,我几乎得不到半点有关 plot_surface 的重要参数说明,而且我感觉纯英文的源...
以下是一个基本的plot_surface使用示例: importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3D# 生成数据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))# 创建3D图形fig=plt.figure(figsize=(10,8))ax=fig.add_...
5,0.25)Y=np.arange(-5,5,0.25)X,Y=np.meshgrid(X,Y)Z=np.sin(np.sqrt(X**2+Y**2))ax.plot_surface(X,Y,Z,cmap='viridis')ax.set_xlabel('X Label')ax.set_ylabel('Y Label')ax.set_zlabel('Z Label')ax.set_title('3D Surface Plot')plt.show()...
ax = fig.add_subplot(111, projection='3d')# 绘制三维曲面图surf = ax.plot_surface(X, Y, Z, cmap=cm.viridis)# 添加颜色条fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5)# 显示图形plt.show()# 保存图形plt.savefig('3d_surface_plot.png', dpi=300)...
from mpl_toolkits.mplot3d import Axes3D 然后使用下面的两种方式之一声明要创建三维子图: ax = fig.gca(projection='3d') ax = plt.subplot(111, projection='3d') 接下来就可以使用ax的plot()方法绘制三维曲线、plot_surface()方法绘制三维曲面、scatter()方法绘制三维散点图或bar3d()方法绘制三维柱状图了。
fig= plt.figure()#定义图像窗口ax = Axes3D(fig)#在窗口上添加3D坐标轴ax.plot_surface(X, Y, Z, rstride =1,#rows stride:指定行的跨度为1(只能是int)cstride =1,#columns stride:指定列的跨度为1cmap = plt.get_cmap('Spectral')) ax.contourf(X, Y, Z, zdir='x',offset = -4)#创建在xz...
二、曲面图 Axes3D.plot_surface() 通过曲面图可以绘制出立体的曲面,其语法为 axes3D.plot_surface(x,y,z,其它参数) x,y为水平方向的坐标,z表示函数的高度起伏。这里的x,y应是np.meshgrid()形成的二维方向数组。 参数rcount,ccount, rstride,cstride用法同Axes3D.plot_wireframe()。
surf = ax.plot_surface(X, Y, Z, cmap='viridis') 显示图形: 最后,使用plt.show()来显示绘制好的三维曲面图。 python plt.show() 完整的代码示例如下: python import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np # 创建数据 x = np.linspace(-5, 5,...
3D surface (colormap)matplotlib.org/stable/gallery/mplot3d/surface3d.html https://ikuz.eu/machine-learning-and-computer-science/the-concept-of-conjugate-gradient-descent-in-python/ikuz.eu/machine-learning-and-computer-science/the-concept-of-conjugate-gradient-descent-in-python/ 有: testpr...
fig2=plt.figure()az=fig2.gca(projection='3d')az.plot_surface(X,Y,Z,rstride=8,cstride=8,alpha=0.3)cset=az.contour(X,Y,Z,zdir='z',offset=min(Z)-1,cmap=cm.coolwarm)cset=az.contour(X,Y,Z,zdir='x',offset=min(X)-1,cmap=cm.coolwarm)cset=az.contour(X,Y,Z,zdir='y',offset...