Representing 4D data in mplot 3D using colormaps

前端 未结 2 645
遥遥无期
遥遥无期 2020-12-17 05:24

Is there a way to change the value that the colormap is tied to in an mplot3d surface plot?
As an example, I\'m trying to represent surface temperature for an object:

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 05:51

    In case you are looking for a colorbar too do the following

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection='3d')
    p_surf=ax.plot_surface(x,y,z,rstride=1,cstride=1,linewidth=0,antialiased=True,facecolors=cm.jet(np.sqrt(x*x + y*y + z*z)))
    m = cm.ScalarMappable(cmap=cm.jet)
    m.set_array(x*x + y*y + z*z)
    plt.colorbar(m)
    plt.show()
    

提交回复
热议问题