Python. Draw rectangle in basemap
- by user2928318
I need to add several rectangles in my basemap. I nee four rectangles with lat and log ranges as below.
1) llcrnrlon=-10, urcrnrlon=10, llcrnrlat=35,urcrnrlat=60
2) llcrnrlon=10.5, urcrnrlon=35, llcrnrlat=35,urcrnrlat=60
3) llcrnrlon=35.5, urcrnrlon=52, llcrnrlat=30,urcrnrlat=55
4) llcrnrlon=-20, urcrnrlon=35, llcrnrlat=20,urcrnrlat=34.5
My script is below. I found "polygon" packages to add lines but I do not exactly know how to do. Please help me!! Thanks a lot for your help in advance!
from mpl_toolkits.basemap import Basemap
m=basemaputpart.Basemap(llcrnrlon=-60, llcrnrlat=20, urcrnrlon=60, urcrnrlat=70, resolution='i', projection='cyl', lon_0=0, lat_0=45)
lon1=np.array([[-180.+j*0.5 for j in range(721)] for i in range(181)])
lat1=np.array([[i*0.5 for j in range(721)] for i in range(181) ])
Nx1,Ny1=m(lon1,lat1,inverse=False)
toplot=data[:,:]
toplot[data==0]=np.nan
toplot=np.ma.masked_invalid(toplot)
plt.pcolor(Nx1,Ny1,np.log(toplot),vmin=0, vmax=5)
cbar=plt.colorbar()
m.drawcoastlines(zorder=2)
m.drawcountries(zorder=2)
plt.show()