Python
matplotlib
Basemap

basemapに複数のグラフを重ねる

More than 1 year has passed since last update.

マップ上の座標を指定して新たなグラフを重ねるコード。

axes_on_basemap.ry
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from mpl_toolkits.basemap import  Basemap


space = 0.05
size = 0.9
lonmin = -180.
lonmax = 180.
latmin = -90.
latmax = 90.
span = 30.

v = np.arange(180*360).reshape(180,360) #If basemap is used, reverse is not necessary. 
px,py = np.meshgrid(np.arange(-180,180,10.), np.arange(-90,90,10.))

fig = plt.figure(figsize=(20,10),dpi=80)
ax = fig.add_axes([space,space,size,size])
m = Basemap(resolution='l',llcrnrlat=latmin,llcrnrlon=lonmin,urcrnrlat=latmax,urcrnrlon=lonmax,ax=ax)

m.imshow(v,cmap=cm.cool,interpolation='nearest')
ax.scatter(px,py,s=4,c='r')
m.drawcoastlines(linewidth=0.5,color='white')
m.drawparallels(np.arange(latmin,latmax+1,span),linewidth=0.3)
m.drawmeridians(np.arange(lonmin,lonmax+1,span),linewidth=0.3)   

ax.set_xticks(np.arange(lonmin,lonmax+1,span))
ax.set_xticklabels(map(str,np.arange(lonmin,lonmax+1,span)),fontsize=16)
ax.set_yticks(np.arange(latmin,latmax+1,span))
ax.set_yticklabels(map(str,np.arange(latmin,latmax+1,span)),fontsize=16)

subsize = 0.1
subax=[]
coordinates = zip(np.arange(lonmin,lonmax,60),np.arange(latmin,latmax,span))
for i,(lon,lat) in enumerate(coordinates):
    x = space + (lon - lonmin) / (lonmax - lonmin) * size
    y = space + (lat - latmin) / (latmax - latmin) * size
    subax.append(fig.add_axes([x,y,subsize,subsize]))
    subax[i].text(0.5,0.5,i,size=36,ha='center',va='center')
plt.show()

basemaptest.png