代码之家  ›  专栏  ›  技术社区  ›  user906357

通过Python创建具有2个平面和颜色映射的图

  •  0
  • user906357  · 技术社区  · 7 年前

    我有两个2D阵列,我想用它生成一个类似于休耕的图像,只是在轴上有不同的限制。

    enter image description here

    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from matplotlib import cm
    from matplotlib.ticker import LinearLocator, FormatStrFormatter
    import numpy as np
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.set_xlim(-2.01, 2.01)
    ax.set_ylim(-2.01, 2.01)
    ax.set_zlim(-2.01, 2.01)
    cmap = plt.cm.gray
    im = ax.imshow(np.asarray(array1), cmap=cmap)
    im.remove()
    fig.colorbar(im)
    plt.show()
    

    0 回复  |  直到 7 年前
        1
  •  1
  •   keineahnung2345 Daniel Ballinger    7 年前

    Matplotlib - Plot a plane and points in 3D simultaneously ,我能够做到这一点:

    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    from matplotlib import cm
    from matplotlib.ticker import LinearLocator, FormatStrFormatter
    import numpy as np
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)
    ax.set_zlim(0, 1)
    
    ax.set_xticks([0, 0.2, 0.4, 0.6, 0.8, 1])
    ax.set_yticks([0, 0.5, 1])
    ax.set_zticks([0, 0.2, 0.4, 0.6, 0.8, 1])
    cmap = plt.cm.gray
    
    #plot vertical surface
    y = 0.5
    xx, zz = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10))
    p = ax.plot_surface(xx, y, zz, cmap=cmap, alpha=0.5)
    
    x = 0.2
    yy, zz = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10))
    p = ax.plot_surface(x, yy, zz, cmap=cmap, alpha=0.5)
    
    fig.colorbar(p)
    plt.show()
    

    注意,我没有使用 normal dot 竖的

    以下是我得到的(我正在进行正确的遮挡):

    enter image description here