Surface and 3d contour in matplotlib

后端 未结 2 2005
心在旅途
心在旅途 2020-12-15 07:16

I would like to plot a surface with a colormap, wireframe and contours using matplotlib. Something like this:

Notice that I am not asking about

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 07:45

    Apparently it is a bug, if you try this

    import numpy as np
    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection="3d")
    X, Y = np.mgrid[-1:1:30j, -1:1:30j]
    Z = np.sin(np.pi*X)*np.sin(np.pi*Y)
    
    
    ax.plot_surface(X, Y, Z, cmap="autumn_r", lw=0, rstride=1, cstride=1)
    ax.contour(X, Y, Z+1, 10, lw=3, colors="k", linestyles="solid")
    plt.show()
    

    And rotate around, you will see the contour lines disappearing when they shouldn't

提交回复
热议问题