How to draw rectangles on a Basemap

前端 未结 3 1481
暖寄归人
暖寄归人 2020-12-09 10:34

I\'m looking for a way to plot filled rectangles on a Basemap. I could easily draw the rectangle\'s edges using the drawgreatcircle method, but I cannot find a

3条回答
  •  执笔经年
    2020-12-09 10:59

    Similar answer to above, but more basic code:

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    from matplotlib.patches import Polygon
    
    map = Basemap(projection='cyl')
    
    map.drawmapboundary(fill_color='aqua')
    map.fillcontinents(color='coral',lake_color='aqua')
    map.drawcoastlines()
    
    x1,y1 = map(-25,-25)
    x2,y2 = map(-25,25)
    x3,y3 = map(25,25)
    x4,y4 = map(25,-25)
    poly = Polygon([(x1,y1),(x2,y2),(x3,y3),(x4,y4)],facecolor='red',edgecolor='green',linewidth=3)
    plt.gca().add_patch(poly)
    
    plt.show()
    

提交回复
热议问题