Python folium で、
前提
以下環境で
OS
% sw_vers ProductName: Mac OS X ProductVersion: 10.12.6 BuildVersion: 16G29
pythonの
verion % python -V Python 2.7.10
使用した
folium の version % pip list | grep folium folium (0.5.0)
ドキュメントでの 記載
folium — Folium 0.5.0+15.gecd5052 documentation に
- fill_color (string, default ‘blue’) – Area fill color. Can pass a hex code, color name, or if you are binding data, one of the following color brewer palettes: ‘BuGn’, ‘BuPu’, ‘GnBu’, ‘OrRd’, ‘PuBu’, ‘PuBuGn’, ‘PuRd’, ‘RdPu’, ‘YlGn’, ‘YlGnBu’, ‘YlOrBr’, and ‘YlOrRd’.
デフォルトはblue
で、
計12種類ですね。
- ‘BuGn’
- ‘BuPu’
- ‘GnBu’
- ‘OrRd’
- ‘PuBu’
- ‘PuBuGn’
- ‘PuRd’
- ‘RdPu’
- ‘YlGn’
- ‘YlGnBu’
- ‘YlOrBr’
- ‘YlOrRd’
実装上での 記載
どのように
folium/folium.py at master · python-visualization/folium でcolor_brewer
と
if data is not None and not color_brewer(fill_color):
このメソッドは、from branca.utilities import color_brewer
で、branca
と
branca
は、
python-visualization/branca
こちらの
* color_brewerの
scheme_info = {'BuGn': 'Sequential', 'BuPu': 'Sequential', 'GnBu': 'Sequential', 'OrRd': 'Sequential', 'PuBu': 'Sequential', 'PuBuGn': 'Sequential', 'PuRd': 'Sequential', 'RdPu': 'Sequential', 'YlGn': 'Sequential', 'YlGnBu': 'Sequential', 'YlOrBr': 'Sequential', 'YlOrRd': 'Sequential', 'BrBg': 'Diverging', 'PiYG': 'Diverging', 'PRGn': 'Diverging', 'PuOr': 'Diverging', 'RdBu': 'Diverging', 'RdGy': 'Diverging', 'RdYlBu': 'Diverging', 'RdYlGn': 'Diverging', 'Spectral': 'Diverging', 'Accent': 'Qualitative', 'Dark2': 'Qualitative', 'Paired': 'Qualitative', 'Pastel1': 'Qualitative', 'Pastel2': 'Qualitative', 'Set1': 'Qualitative', 'Set2': 'Qualitative', 'Set3': 'Qualitative', }
colorbrewer
がRColorBrewer |
ソースコードに
実際に 使用できるか 確認する
Document に
テストに
前回map出力に
folium_example/fill_color_test at master · kemsakurai/folium_example
threshold_scale を
6要素指定して 実行
以下、スクリプトの 抜粋です。 YlOrRd まで# 以下、threshold_scale を指定してcolorが出力できるか確認する m.choropleth(geo_data=data, data=df, columns=['A', 'AH'], key_on='feature.id', fill_color=color, threshold_scale=[0.9, 3.5, 7, 10, 15, 27], line_opacity=0.5, reset=True)
出力が 成功しました。 BrBg 以降はBuGn :ok BuPu :ok GnBu :ok OrRd :ok PuBu :ok PuBuGn :ok PuRd :ok RdPu :ok YlGn :ok YlGnBu :ok YlOrBr :ok YlOrRd :ok BrBg :ng PiYG :ng PRGn :ng PuOr :ng RdBu :ng RdGy :ng RdYlBu :ng RdYlGn :ng Spectral :ng Accent :ng Dark2 :ng Paired :ng Pastel1 :ng Pastel2 :ng Set1 :ng Set2 :ng Set3 :ng
出力に 失敗しています。 threshold_scale 未指定で
実行
以下スクリプトの抜粋です。 Spectral まで# threshold_scale 未指定で実行 m.choropleth(geo_data=data, data=df, columns=['A', 'AH'], key_on='feature.id', fill_color=color, line_opacity=0.5, reset=True)
出力に 成功しました。 動作とBuGn :ok BuPu :ok GnBu :ok OrRd :ok PuBu :ok PuBuGn :ok PuRd :ok RdPu :ok YlGn :ok YlGnBu :ok YlOrBr :ok YlOrRd :ok BrBg :ok PiYG :ok PRGn :ok PuOr :ok RdBu :ok RdGy :ok RdYlBu :ok RdYlGn :ok Spectral :ok Accent :ng Dark2 :ng Paired :ng Pastel1 :ng Pastel2 :ng Set1 :ng Set2 :ng Set3 :ng
しては、 threshold_scale 未指定だと、 6色の Colorスケールに なるため、 使用できる カラースキーマが 増えるのかと 思いました。
scheme_info
で、Qualitative と 定義されている カラースキーマの 出力が うまくいなかないようです。
実装上、以下のように、 Qualitative
の場合は、 6色で 固定しないと 出力できないような 実装に なっていましたので、 threshold_scaleの 指定を 5に してみます。 1
6色固定と読み 取ったのですが、 スクリプトで、 threshold_scale を 4要素に しても 問題なく 動作しました。 color_brewerの
抜粋 # Only if n is greater than six do we interpolate values. if n > 6: if core_color_code not in schemes: color_scheme = None else: # Check to make sure that it is not a qualitative scheme. if scheme_info[core_color_code] == 'Qualitative': raise ValueError("Expanded color support is not available" " for Qualitative schemes, restrict" " number of colors to 6")
threshold_scale 5つ
指定して 実行
以下はスクリプトの 抜粋です。 こちらは# threshold_scale 5つ指定して出力 m.choropleth(geo_data=data, data=df, columns=['A', 'AH'], key_on='feature.id', fill_color=color, threshold_scale=[0.9, 3.5, 7, 15, 27], line_opacity=0.5, reset=True)
全て 成功しました。 カラースキーマのBuGn :ok BuPu :ok GnBu :ok OrRd :ok PuBu :ok PuBuGn :ok PuRd :ok RdPu :ok YlGn :ok YlGnBu :ok YlOrBr :ok YlOrRd :ok BrBg :ok PiYG :ok PRGn :ok PuOr :ok RdBu :ok RdGy :ok RdYlBu :ok RdYlGn :ok Spectral :ok Accent :ok Dark2 :ok Paired :ok Pastel1 :ok Pastel2 :ok Set1 :ok Set2 :ok Set3 :ok
Sequential
、Diverging
、Qualitative
についてですが、 以下サイトに 解説が ありました。
ちずのつくりかた: 配色: 地理空間への 招待状
まとめ
folium の
ドキュメントの
通り、 連続値 Sequential
と呼ばれる カラースキーマである 12の カラースキーマが 使用できる。 threshold_scale を
未指定(None)に すると、 (発散型?) Diverging
カラースキーマが使用できる。 threshold_scale を
5以下で 指定すると、 Qualitative
も含めて、 全ての カラースキーマが 使用できる。 GIS を
触った ことなどなかったので、 知らない ことだらけで 勉強にはなる。が、 勉強ばかりであまり 進捗しない。
以上です。
コメント