Matplotlib: imshow in 3d plot

后端 未结 1 1288
借酒劲吻你
借酒劲吻你 2021-02-15 20:54

In the plot below, taken from matplotlib\'s gallery, contourf is used to create a 2d plot beneath the 3d one. My question is, is it possible to use imshow to do the same thing?

1条回答
  •  借酒劲吻你
    2021-02-15 21:24

    Just specify the levels= option for the contourf, e.g.

    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as plt,numpy as np
    plt.clf()
    fig = plt.figure(1)
    ax = fig.gca(projection='3d')
    X, Y, Z = axes3d.get_test_data(0.05)
    ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
    cset = ax.contourf(X, Y, Z, zdir='z', offset=-100,
            levels=np.linspace(-100,100,1200),cmap=plt.cm.jet)
    cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=plt.cm.jet)
    cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=plt.cm.jet)
    ax.set_xlabel('X')
    ax.set_xlim(-40, 40)
    ax.set_ylabel('Y')
    ax.set_ylim(-40, 40)
    ax.set_zlabel('Z')
    ax.set_zlim(-100, 100)    
    plt.show()
    

    The image

    0 讨论(0)
提交回复
热议问题