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
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()
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()