CartopyはpythonでGISデータを扱うためのパッケージです. 同じ用途としてBasemapというものもありますが、そちらは開発が終了しているようなので、今から始めるならCartopyが無難かなと思います.
import matplotlib.pyplot as plt #描画
import cartopy.crs as ccrs #cartopy
fig = plt.figure()
ax = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude= 180))
ax.coastlines(lw=0.5)
plt.show()
fig = plt.figure()
ax = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude= 180))
ax.coastlines(lw=0.5)
### 経度線・緯度線を引く ###
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
gl = ax.gridlines(linestyle='-', color='gray',draw_labels=True)
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': 12}
gl.ylabel_style = {'size': 12}
plt.show()
fig = plt.figure()
ax = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude= 180))
ax.coastlines(lw=0.5)
### 任意の間隔で経度線・緯度線を引く ###
import numpy as np
import matplotlib.ticker as mticker
gl = ax.gridlines(linestyle='-', color='gray',draw_labels=True)
gl.xlocator = mticker.FixedLocator(np.arange(-180,180,30))
gl.ylocator = mticker.FixedLocator(np.arange(-90,90,30))
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': 12}
gl.ylabel_style = {'size': 12}
plt.show()
fig = plt.figure()
ax = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude= 180))
ax.coastlines(lw=0.5)
### ラベルのみ設定する ###
from cartopy.mpl.ticker import LatitudeFormatter,LongitudeFormatter
### 目盛を描く緯度経度の値を設定 ###
ax.set_xticks(np.arange(0,360.1,60),crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-90,90.1,30),crs=ccrs.PlateCarree())
### 目盛の表示形式を度数表記にする ###
latfmt = LatitudeFormatter()
lonfmt = LongitudeFormatter(zero_direction_label=True)
ax.xaxis.set_major_formatter(lonfmt)
ax.yaxis.set_major_formatter(latfmt)
ax.axes.tick_params(labelsize=12)
plt.show()
import cartopy.feature as cfeature
fig = plt.figure()
ax = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude= 180))
ax.add_feature(cfeature.LAND) ### 地形を塗る
ax.coastlines(lw=0.5)
ax.set_xticks(np.arange(0,360.1,60),crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-90,90.1,30),crs=ccrs.PlateCarree())
latfmt = LatitudeFormatter()
lonfmt = LongitudeFormatter(zero_direction_label=True)
ax.xaxis.set_major_formatter(lonfmt)
ax.yaxis.set_major_formatter(latfmt)
ax.axes.tick_params(labelsize=12)
plt.show()
軸回りを全て指定し終わってからが良い?
fig = plt.figure()
ax = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude= 180))
ax.add_feature(cfeature.LAND) ### 地形を塗る
ax.coastlines(lw=0.5)
ax.set_xticks(np.arange(0,360.1,60),crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-90,90.1,30),crs=ccrs.PlateCarree())
latfmt = LatitudeFormatter()
lonfmt = LongitudeFormatter(zero_direction_label=True)
ax.xaxis.set_major_formatter(lonfmt)
ax.yaxis.set_major_formatter(latfmt)
ax.axes.tick_params(labelsize=12)
ax.set_extent([120,270,10,70],ccrs.PlateCarree()) ### 描画範囲を指定
plt.show()
ccrs.PlateCarree : 緯度経度は(x,y)
ccrs.LambertConformal : 緯度経度は(r,phi)
ccrs.NorthPolarStereo : 北極中心の図
title = ['PlateCarree','LambertConformal','NorthPolarStereo']
fig = plt.figure(figsize=(15,20))
ax1 = fig.add_subplot(1,3,1, projection=ccrs.PlateCarree(central_longitude= 180))
ax2 = fig.add_subplot(1,3,2, projection=ccrs.LambertConformal(central_longitude=180,central_latitude=40))
ax3 = fig.add_subplot(1,3,3, projection=ccrs.NorthPolarStereo(central_longitude=180))
for ax in ([ax1, ax2, ax3]):
ax.add_feature(cfeature.LAND)
ax.coastlines(lw=0.5)
gl = ax.gridlines(linestyle='-', color='gray',draw_labels=False)
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': 12}
gl.ylabel_style = {'size': 12}
#ax.set_extent([120,270,10,70],ccrs.PlateCarree())
plt.show()
ax.coastlines : 解像度をresolutionで10m,50m,110mと指定可能
fig = plt.figure(figsize=(15,20))
ax1 = fig.add_subplot(1,3,1, projection=ccrs.PlateCarree(central_longitude= 180))
ax2 = fig.add_subplot(1,3,2, projection=ccrs.PlateCarree(central_longitude= 180))
ax3 = fig.add_subplot(1,3,3, projection=ccrs.PlateCarree(central_longitude= 180))
for scale, ax in zip(['110m','50m','10m'],[ax1, ax2, ax3]):
ax.add_feature(cfeature.LAND,color='yellowgreen')
ax.coastlines(resolution=scale,lw=0.5)
ax.set_extent([110,160,10,60],ccrs.PlateCarree())
plt.show()
plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=195))
ax.add_feature(cfeature.LAND)
ax.coastlines(resolution='50m',lw=0.5)
ax.set_extent([110,160,10,60],ccrs.PlateCarree()) # 表示範囲を限定
ax.plot(140.52,38.27,'o',transform=ccrs.PlateCarree(),markersize=3,color='r') # 任意の点をプロット
ax.text(141.52,39.27,'Sendai',size=12,color='red',transform=ccrs.PlateCarree()) # 任意のところに文字を打つ
#plt.savefig('map.png',bbox_inches='tight',pad_inches=0.1) ### 図を保存する
plt.show()
plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
ax.add_feature(cfeature.LAND)
ax.coastlines(resolution='50m',lw=0.5)
ax.set_extent([110,160,10,60],ccrs.PlateCarree()) # 表示範囲を限定
ax.plot(140.52,38.27,'o',transform=ccrs.PlateCarree(),markersize=3,color='r') # 任意の点をプロット
ax.text(141.52,39.27,'Sendai',size=12,color='red',transform=ccrs.PlateCarree()) # 任意のところに文字を打つ
import matplotlib.patches as patches
r = patches.Rectangle(xy=(-60,20),width=10,height=10,fill=False,linewidth=5,color='red') # boxを作成
ax.add_patch(r)
x = [120,120,130,130,120] #[左下、左上、右上、右下、左下]
y = [20,30,30,20,20]
ax.fill(x,y,transform=ccrs.PlateCarree(),color='coral', alpha=0.4) #色塗り
plt.show()