こんな人にオススメ
plotly
のgo.Layout
の引数になるgeo
にprojection
っていう引数があって、これでマップの図法を変更できる。けど、どんな図法があるの?
ということで、今回はplotly
のgo.Layout
の引数となるgeo
(layout.geo
)の引数projection
で選択可能な図法を全てマップ化してみる。
図法の総数は脅威の83ということで恐ろしいことありゃしない。そもそもgeo
を使用する人がそこまでいるかわからんけど、一覧がないから作ってみる。
ただし、83全てをこの記事に載せると記事が激重になるので、以下の4つのアルファベットに分けて記事を書くことにする。基準は先頭の文字。
- aからd
- eからg
- hからn
- oからz
今回は先頭文字がhからnの図法を描いてみる。その他の図法は以下。
-
【plotly&layout.geo】projectionのtype一覧(名称先頭がa~d編)
続きを見る
続きを見る 続きを見る【plotly&layout.geo】projectionのtype一覧(名称先頭がe~g編)
【plotly&layout.geo】projectionのtype一覧(名称先頭がo~z編)
目次(クリック・タップでジャンプ)
- 1 マップ作成
- 2 projection_type一覧(h~n)
- 2.1 hammer
- 2.2 hill
- 2.3 homolosine
- 2.4 hufnagel
- 2.5 hyperelliptical
- 2.6 kavrayskiy7
- 2.7 lagrange
- 2.8 larrivee
- 2.9 laskowski
- 2.10 loximuthal
- 2.11 mercator
- 2.12 miller
- 2.13 mollweide
- 2.14 mt flat polar parabolic
- 2.15 mt flat polar quartic
- 2.16 mt flat polar sinusoidal
- 2.17 natural earth
- 2.18 natural earth1
- 2.19 natural earth2
- 2.20 nell hammer
- 2.21 nicolosi
- 3 関連記事
マップ作成
ということで早速マップ作成を行う。今回はマップの描き方、図法がメインになるのでplotly
の「Mixed Subplots in Python」の火山の位置データを使用する。
下準備
import pandas as pd import plotly.graph_objects as go import plotly.io as pio
下準備のimport
関連。pandas
でデータを読み込み・整理し、go
でマップ化、そしてpio
で保存。
データの読み込み
# 火山データの取得 file = '<https://raw.githubusercontent.com/plotly/datasets/master/volcano_db.csv>' df = pd.read_csv(file, encoding='iso-8859-1',) print(df.columns.values) # ['Number' 'Volcano Name' 'Country' 'Region' 'Latitude' 'Longitude' 'Elev' # 'Type' 'Status' 'Last Known']
GitHubに火山のデータがあるようなのでこれを読み込み。ヘッダーには番号や名前などが記載されている。今回は座標と火山の名称を使用することとする。
マップ化
# projection_typeをいじって色々な図法を試す for num, projection_type in enumerate(projection_types): plot = [ go.Scattergeo( lat=df['Latitude'], lon=df['Longitude'], text=df['Volcano Name'], # 追加テキストは火山の名称 marker_color='crimson', # マーカーの色は赤系 marker_symbol='triangle-up' # マーカーは上向き三角 ), ] layout = go.Layout( # マップタイトルを作成 title=f'{num}: {projection_type}', geo=dict( # 図法を設定 projection_type=projection_type, # 緯度・経度の線を表示 lataxis_showgrid=True, lonaxis_showgrid=True, ), ) fig = go.Figure(data=plot, layout=layout) # fig.show() pio.orca.config.executable = '/Applications/orca.app/Contents/MacOS/orca' pio.write_html(fig, f'{projection_type}.html', ) pio.write_image(fig, f'{projection_type}.png')
今回は特に説明せずにサクッと作成。Scattergeo
については以下の記事参照。
-
【plotly&Scattergeo】世界地図に各国の首都の位置をプロット
続きを見る
projection_type
一覧(h~n)
ということでprojection_type
のうち、先頭アルファベットがh~nのものをマップ化。マップは動かせるようにしてあるので、自由にグリグリしていただきたい。