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_subplot(111,projection='3d')# 绘制表面surf=ax.plot_surface(X,Y,Z,cmap='viridis')# 添加颜色条fig.colorbar(surf,shrink...
# cmap是颜色映射表 # from matplotlibimportcm # ax.plot_surface(X,Y,Z,rstride=1,cstride=1,cmap=cm.coolwarm)# cmap="rainbow"亦可 # 我的理解的 改变cmap参数可以控制三维曲面的颜色组合,一般我们见到的三维曲面就是 rainbow 的 # 你也可以修改 rainbow 为 coolwarm,验证我的结论 ax.plot_surface(X,Y...
使用曲面渐变的颜色可以使得曲面图更加生动和具有层次感。在plot_surface函数中,可以通过设置cmap参数来指定颜色映射,常用的颜色映射有"viridis"、"jet"、"coolwarm"等。颜色映射可以根据曲面高度的不同,自动为曲面上的每个点分配不同的颜色,从而实现曲面渐变的效果。
在使用Python的matplotlib库中的plot_surface函数绘图时,cmap参数指的是颜色映射表(colormap)。这个参数用于控制曲面的颜色样式,根据不同的数据值显示不同的颜色。matplotlib支持多种颜色映射表,可以分为几个大类: 连续色彩映射(Sequential colormaps):主要用于表示从低到高的数据范围。比如viridis, plasma, inferno, ma...
plot_surface(x1, x2, zs, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0) plt.show() windows11+powershell PS D:\work\python_work\ModernPython\codes\matplotlib\surface_plot\01> py.exe .\testprj.py 为便于检索,文章收录于: 迦非喵:Matplotlib绘图系列链接整理0 赞同 · 0 评论文章...
fig=plt.figure()ax=fig.add_subplot(111,projection='3d')X=np.arange(-5,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')plt.show() Python Copy
(x_test, y_test)Ztest = Xtest**-1 + Ytestsurf = ax.plot_surface(Xtest, Ytest, Ztest, cmap=cm.plasma, alpha=1, antialiased=False)fig.colorbar(surf, shrink=0.5, aspect=5)ax.set_ylabel(r'$ Y $', fontsize=16)ax.set_xlabel(r'$ X $', fontsize=16)ax.set_zlabel(r'$ Z...
(-5,5,50)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')ax.set_ylabel('Y')ax.set_zlabel('Z')ax.set_title('3D Surface Plot')plt.show(...
# 画曲面图 # 行和列对应的跨度 # 设置颜色ax.plot_surface(X, Y, Z, rstride = 1, cstride = 1, cmap = plt.get_cmap('rainbow'))plt.show() 以上是matplotlib基于测试数据的数据可视化,结合实际项目中数据,代码稍加修改,即可有让人印象深刻的效果。
SurfacePlot ContourPlot FilledContourPlot PolygonPlot BarPlot Text 写在篇后 写在篇前 matplotlib也支持三维作图,但是相对于matlab来讲,感觉功能更弱。当然话说回来,三维作图用的场景相对也更少,所以呢,有一定的知识储备就够了。matplotlib绘制三维图形依赖于mpl_toolkits.mplot3d,用法也比较简单,只需要一个...