5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-10-15

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

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

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?