Pythn의 세계지도-25(cartopy에서 Natural Earth 데이터 사용)
운영 환경
UbuntuStudio 18.04
Python 3.6.5
참고 자료
The cartopy Feature interface
https://scitools.org.uk/cartopy/docs/v0.15/matplotlib/feature_interface.html
파이썬 세계지도 - 3 (일본지도)
https://qiita.com/ty21ky/items/b59e7d9e4b164a803c1f
설치하다.
NameError: name 'cartopy' is not defined
등의 오류가 발생하면 포장이 부족해 설치가 필요하다.
포장을 찾는 방법(Ubuntu의 경우)
$ pip search Cartopy
Cartopy (0.16.0) - A cartographic python library with Matplotlib support for visualisation
설치 예(Ubuntu 시)$ pip install Cartopy
#!/usr/bin/python3
# coding: UTF-8
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from matplotlib.offsetbox import AnchoredText
import cartopy.io.shapereader as shpreader #シェイプファイルを使用
font = {'family':'IPAGothic'} #日本語Fontを指定
def main():
#シェイプファイル
fname = 'ne_10m_admin_1_states_provinces/ne_10m_admin_1_states_provinces.shp' #国境線を表示
shapes = list(shpreader.Reader(fname).geometries())
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_geometries(shapes, ccrs.PlateCarree(), edgecolor='red', facecolor='gray', alpha=0.3)
ax.set_extent([80, 170, -45, 45]) #[lon1,lon2,lat1,lat2]
ax.stock_img() #陸地・海底の形状を表示
# Create a feature for States/Admin 1 regions at 1:50m from Natural Earth
states_provinces = cfeature.NaturalEarthFeature(
category='cultural',
name='admin_1_states_provinces_lines',
scale='10m', #'50m',
facecolor='none')
SOURCE = 'Natural Earth'
LICENSE = 'public domain'
ax.coastlines(resolution='10m') #海岸線 下のax.add_feature(cfeature.COASTLINE) どちらか必要
#ax.add_feature(cfeature.LAND) #この塗りつぶしも荒い
#ax.add_feature(cfeature.COASTLINE) #この海岸線は荒い
ax.add_feature(states_provinces, edgecolor='gray') #県境を表示(全世界)
# ライセンス情報のテキスト注釈を右下に追加します。
text = AnchoredText(r'$\mathcircled{{c}}$ {}; license: {}'
''.format(SOURCE, LICENSE),
loc=4, prop={'size': 12}, frameon=True)
ax.add_artist(text)
plt.title('東アジア', **font)
plt.show()
if __name__ == '__main__':
main()
cartopy Rotated pole boxes
회전하는 극좌표계에서 상자를 정의할 때 상자를 뒤집는 방법
참고 자료
Rotated pole boxes
https://scitools.org.uk/cartopy/docs/v0.15/examples/rotated_pole.html
Cartopy projection list
https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html
#!/usr/bin/python3
# coding: UTF-8
"""
回転ポールボックス
------------------
この例は、回転した極座標系でボックスが定義されているときに、ボックスが反る方法を示しています。
ポリゴンにポールを含めることの効果を見るには、 `` box_top``を `` 44``、 `` 46``、 `` 75``に変更してみてください。
"""
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
def main(): #回転しない基準 北緯90度 東経0度が上
rotated_pole = ccrs.RotatedPole(pole_latitude=45, pole_longitude=180) #地図の種類
#基準 北緯45度 東経180度が上
box_top = 75
x, y = [-44, -44, 45, 45, -44], [-45, box_top, box_top, -45, -45] #[左下、左上、右上、右下、左下]
ax = plt.subplot(311, projection=rotated_pole)
ax.stock_img() #陸地・海底の形状
ax.coastlines() #海岸線
ax.plot(x, y, marker='o', transform=rotated_pole) #点
ax.fill(x, y, color='coral', transform=rotated_pole, alpha=0.4) #BOX
ax.gridlines()
ax = plt.subplot(312, projection=ccrs.PlateCarree()) #地図の種類
ax.stock_img()
ax.coastlines()
ax.plot(x, y, marker='o', transform=rotated_pole)
ax.fill(x, y, transform=rotated_pole, color='coral', alpha=0.4)
ax.gridlines()
'''
ax = plt.subplot(313, projection=ccrs.AlbersEqualArea(central_longitude=130.0)) #地図の種類
ax.stock_img()
ax.coastlines()
ax.plot(x, y, marker='o', transform=rotated_pole)
ax.fill(x, y, transform=rotated_pole, color='coral', alpha=0.4)
ax.gridlines()
ax = plt.subplot(313, projection=ccrs.LambertConformal(central_longitude=-96.0, central_latitude=39.0)) #地図の種類
ax.stock_img()
ax.coastlines()
ax.plot(x, y, marker='o', transform=rotated_pole)
ax.fill(x, y, transform=rotated_pole, color='coral', alpha=0.4)
ax.gridlines()
ax = plt.subplot(313, projection=ccrs.LambertCylindrical(central_longitude=130.0)) #地図の種類
ax.stock_img()
ax.coastlines()
ax.plot(x, y, marker='o', transform=rotated_pole)
ax.fill(x, y, transform=rotated_pole, color='coral', alpha=0.4)
ax.gridlines()
'''
ax = plt.subplot(313, projection=ccrs.Mercator(central_longitude=130.0)) #地図の種類
ax.stock_img()
ax.coastlines()
ax.plot(x, y, marker='o', transform=rotated_pole)
ax.fill(x, y, transform=rotated_pole, color='coral', alpha=0.4)
ax.gridlines()
plt.show()
if __name__ == '__main__':
main()
Reference
이 문제에 관하여(Pythn의 세계지도-25(cartopy에서 Natural Earth 데이터 사용)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ty21ky/items/2b8a281c85b465ebc6b8텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)