How to draw circle in basemap or add artiste

后端 未结 2 900
日久生厌
日久生厌 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:04

    So I'm not sure the radius that you want your circle in your map, but this code will draw you a circle polygon on top of your map m:

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    from matplotlib.patches import Circle
    
    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") #c croud par defaut, l low , h high , f full
    

    For the circle here, I just arbitrarily chose a radius of 1/3 the entire length of your y-axis...

    circle = Circle(xy=m(5,5),radius=(m.ymax - m.ymin) / 3, fill=False)
    plt.gca().add_patch(circle)
    
    m.drawcoastlines() #dessiner les lignes
    m.drawcountries()
    m.drawstates()
    plt.show()
    

    0 讨论(0)
  • 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()
    

    0 讨论(0)
提交回复
热议问题