plot_surface(x, y, z, facecolors=colors, shade=False) ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label') ax.set_title('Customized 3D Surface Plot with Color Mapping') plt.show() 添加网格线 有时候,我们希望在3D曲面图中添加网格线以帮助更好地理解数据的分布...
frommpl_toolkits.mplot3dimportaxes3dimportmatplotlib.cmascm fig=plt.figure()ax=fig.add_subplot(111,projection='3d')# 创建数据X,Y,Z=axes3d.get_test_data(0.1)# 绘制表面,使用colormap来设置面颜色surf=ax.plot_surface(X,Y,Z,rstride=8,cstride=8,cmap=cm.viridis)# 添加颜色条fig.colorbar(surf...
它使用 matplotlib 的plot_surface函数而不是plot_trisurf。 基本上,您想将 x、y 和 z 变量重塑为相同维度的二维数组。要将第四维添加为颜色图,您必须提供另一个与轴变量具有相同维数的二维数组。 下面是 3d 图的示例代码,其中颜色图对应于 x 值。facecolors参数用于根据您的喜好更改颜色图。请注意,它的值是从...
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors = my_col, linewidth=0, antialiased=False) ax.set_zlim(-1.01, 1.01) 我不会使用 jet,而是使用一些线性颜色图,例如cubehelix。您可以使用错误的颜色图轻松欺骗眼睛(关于该主题的许多帖子之一)...
colors_norm=colors_ref/np.max(colors_ref)#介于(0,1)之间 fig=plt.figure() sub=fig.add_subplot(111,projection='3d')#3d表示三维图像 surf=sub.plot_surface(x_mesh,y_mesh,z_mesh,cmap=plt.cm.Purples,facecolors=plt.cm.Purples(colors_norm))#设置渐变色 ...
这段代码首先创建了一个由数据点构成的3D曲面,然后使用plot_surface方法将其绘制出来。通过face_color参数,我们可以为每个面片指定不同的颜色。在这个例子中,我们使用了6种不同的颜色,并将它们映射到面片上。通过调整alpha参数,可以控制透明度,从而更好地看到颜色的分布。最后,我们使用set_title、set_xlabel、set_yla...
add_subplot(111,projection="3d") surf=sub.plot_surface(x_mesh,y_mesh,z_mesh, cmap=plt.cm.PuRd, facecolors=plt.cm.PuRd(colors_norm)) sub.set_xlabel(r"$x$") sub.set_ylabel(r"$y$") sub.set_zlabel(r"$z$") plt.show() 效果展示:...
cmap A colormap for the surface patches. facecolors Face colors for the individual patches norm An instance of Normalize to map values to colors vmin Minimum value to map vmax Maximum value to map shade Whether to shade the facecolors In [9]: fig = plt.figure() ...: ax = Axes3D(fig...
ax.plot_surface(X + 1e5, Y + 1e5, Z, cmap='autumn', cstride=2, rstride=2) ax.set_xlabel("X label") ax.set_ylabel("Y label") ax.set_zlabel("Z label") ax.set_zlim(0, 2) plt.show() 代码如下: # This import registers the 3D projection, but is otherwise unused. ...
ax.plot_surface(x,y,z,rstride=2,cstride=1,cmap=plt.cm.coolwarm,alpha=0.8) ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') plt.show() 得到的图像如下图所示: 到此,matplotlib基本操作的学习结束了,相信大家也可以基本完成自己的科研任务了。下面将继续学习python的相关课程,请继续关...