Python

Pythonで世界地図-15(詳細地図付き)

参考
Basemap tutorial
http://basemaptutorial.readthedocs.io/en/latest/locator.html

image.png

#!/usr/bin/python3
# coding: UTF-8

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
import numpy as np
import japan_border2 as jb2 #都府県境界線

fig = plt.figure()
ax = plt.axes()

map = Basemap(projection='cyl', lat_0=0, lon_0=147)

map.drawmapboundary(fill_color='aqua')
map.fillcontinents(color='coral',lake_color='aqua', zorder=0.5) # zorder=0だと陸地と海が同じ色、zorder=1または指定しないとドットが地図の後ろに隠れる
map.drawcoastlines()
map.drawcountries() #国境線

lons = np.array([136.539017, 140.224618, -13.2, -96.8, -7.99, 7.5, -17.3, -3.7])
lats = np.array([34.845602, 36.531433, 8.5, 32.7, 12.5, 8.9, 14.7, 40.39])
cases = np.array([20, 20, 6073, 4, 6, 20, 1, 1])

x, y = map(lons, lats)

map.scatter(x, y, s=cases, c='r', alpha=0.9)

axins = zoomed_inset_axes(ax, 20, loc=1)#loc1 : 1(右上), 2(左上), 3(左下), 4(右下)
axins.set_xlim(135, 142)
axins.set_ylim(33, 37)

plt.xticks(visible=True) #visible=Falseと変わらない
plt.yticks(visible=False)

#詳細地図
map2 = Basemap(llcrnrlon=135,llcrnrlat=33,urcrnrlon=142,urcrnrlat=37, ax=axins, resolution = 'i')
map2.drawmapboundary(fill_color='aqua')
map2.fillcontinents(color='coral',lake_color='aqua', zorder=0.5)
map2.drawcoastlines()
map2.drawcountries()
jb2.prefectural_bound(map = map2) #都府県境界線を表示

mark_inset(ax, axins, loc1=2, loc2=4, fc="none", lw=2, ec="b") #詳細地図の設定
#loc1, loc2 : {1(右上), 2(左上), 3(左下), 4(右下)},facecolor(fc),edgecolor(ec) 

map2.scatter(x, y, s=cases/2., c='r', alpha=0.9)

plt.show()