How to draw circle in basemap or add artiste

后端 未结 2 923
日久生厌
日久生厌 2021-01-25 18:39

I want to know how can i plot a circle with Basemap using latitude and longitude.

import matplotlib.pyplot as plt
fig,ax = plt.subplots()
ax.axis([0,10,0,10])
c         


        
2条回答
  •  攒了一身酷
    2021-01-25 19:06

    Having the two codes ready you can just copy the one into the other. The only problem may be that the circle radius needs to be calculated in map coordinates,

    r = 2
    x,y=m(5,5)
    x2,y2 = m(5,5+r) 
    circle1 = plt.Circle((x, y), y2-y, ..)
    

    Complete example:

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    
    fig,ax = plt.subplots()
    
    m = Basemap(projection="mill", #miller est une projection connu
        llcrnrlat =0,#lower left corner latitude
        llcrnrlon =0,
        urcrnrlat =10, #upper right lat
        urcrnrlon =10,
        resolution = "l", ax=ax) #c croud par defaut, l low , h high , f full 
    m.drawcoastlines() #dessiner les lignes
    m.drawcountries()
    m.drawstates()
    m.drawcounties(color="b")
    
    x,y=m(5,5)
    x2,y2 = m(5,5+2) 
    circle1 = plt.Circle((x, y), y2-y, color='black',fill=False)
    ax.add_patch(circle1)
    plt.show()
    

提交回复
热议问题