How to draw polygons with Python?

前端 未结 6 997
南笙
南笙 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:07

    Using matplotlib.pyplot

    import matplotlib.pyplot as plt
    
    coord = [[1,1], [2,1], [2,2], [1,2], [0.5,1.5]]
    coord.append(coord[0]) #repeat the first point to create a 'closed loop'
    
    xs, ys = zip(*coord) #create lists of x and y values
    
    plt.figure()
    plt.plot(xs,ys) 
    plt.show() # if you need...
    

提交回复
热议问题