Plotting 3D Polygons in Python 3

后端 未结 2 760
孤独总比滥情好
孤独总比滥情好 2020-12-17 06:48

In my quest to somehow get 3D polygons to actually plot, I came across the following script (EDIT: modified slightly): Plotting 3D Polygons in python-matplotlib



        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 07:20

    You have to use Poly3DCollection instead of PolyCollection:

    from mpl_toolkits.mplot3d import Axes3D
    from mpl_toolkits.mplot3d.art3d import Poly3DCollection
    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax = Axes3D(fig)
    x = [0,1,1,0]
    y = [0,0,1,1]
    z = [0,1,0,1]
    verts = [zip(x,y,z)]
    ax.add_collection3d(Poly3DCollection(verts), zs=z)
    plt.show()
    

提交回复
热议问题