How to draw polygons with Python?

前端 未结 6 1177
南笙
南笙 2021-02-05 08:38

I have input values of x, y coordinates in the following format:

[[1,1], [2,1], [2,2], [1,2], [0.5,1.5]]

I want to draw polygons, but I don\'t

6条回答
  •  悲哀的现实
    2021-02-05 09:11

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.patches import Polygon
    
    y = np.array([[1,1], [2,1], [2,2], [1,2], [0.5,1.5]])
    
    p = Polygon(y, facecolor = 'k')
    
    fig,ax = plt.subplots()
    
    ax.add_patch(p)
    ax.set_xlim([0,3])
    ax.set_ylim([0,3])
    plt.show()
    

提交回复
热议问题