pythonmatplotlibplotmatplotlib-3d

imshow in 3d plot


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? I would like the colors in the 2d plot to be smoother.

Making the 2d plot seems to be possible because contourf accepts a zdir argument, while I've looked and imshow doesn't. That suggests that it isn't possible, but why not? pcolor would also get the job done, is it possible with that?


Solution

  • 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.add_subplot(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