これは、初めて世界地図を作成し、GeoJSONDataSourceを使用しようとしています。 私は、そのプロパティの国の '大陸'の値に基づいて、パッチに異なる色を割り当てようとしています。Choropleth Map、Bokeh - プロパティ値に基づいてパッチの色を割り当てる
色がキーとして大陸名の辞書で、「大陸」はJSONデータでは、国の大陸値であるp.patches(... fill_color= colours['continent'])
:
は、次の線に沿って何かをすることが可能です。
これは私の現在のコードです:
a =[colours[c['properties']['continent']] for c in json.loads(countries)['features']]
:私はそうのような色の配列にパッチでfill_color属性を設定することによって、少し異なり、これを近づいて試してみました
from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook
import numpy as np
from bokeh.models import GeoJSONDataSource
with open('data.geojson') as c:
countries = (c.read())
geo_source = GeoJSONDataSource(geojson=countries)
colours = {'Europe': 'red', 'Oceania': 'purple', 'Asia': 'blue', 'Africa': 'pink', "South America": 'green', "Antarctica": 'yellow', 'North America': 'orange', "Seven seas (open ocean)": 'red'}
p = figure(height=450, width=900, lod_threshold=1)
p.patches(xs='xs', ys='ys', fill_color='blue', source=geo_source)
p.multi_line(xs='xs', ys='ys', line_color='white', line_width=0.1, source=geo_source)
show(p)
EDIT
このコードをJupyter Notebookで実行すると、次のエラーが表示されます。
Javascript error adding output! Error: attempted to retrieve property array for nonexistent field 'fill_color' See your browser Javascript console for more details.