Skip to content

Instantly share code, notes, and snippets.

@bongole
Last active April 13, 2020 10:00
Show Gist options
  • Save bongole/d9898cbef361b227b100f877a1c72add to your computer and use it in GitHub Desktop.
Save bongole/d9898cbef361b227b100f877a1c72add to your computer and use it in GitHub Desktop.
altair + japan geojson
import altair as alt
import pandas as pd
import random
import requests
#geo_json = requests.get('https://github.com/dataofjapan/land/raw/master/japan.topojson').json()
#japan_geo = alt.Data(
# values=geo_json,
# format=alt.TopoDataFormat(feature='japan',type='topojson')
#)
geo_json = requests.get('https://github.com/dataofjapan/land/raw/master/japan.geojson').json()
japan_geo = alt.Data(values=geo_json, format=alt.DataFormat(property='features',type='json'))
# idが1~47でそれぞれの県に対応している
source = pd.DataFrame({"id": [i + 1 for i in range(47)], "rate": [ random.uniform(0,5) for _ in range(47)]})
alt.Chart(japan_geo).mark_geoshape(
stroke='black',
strokeWidth=1
).encode(
color='rate:Q'
).transform_lookup(
lookup='properties.id',
from_=alt.LookupData(source, 'id', ['rate'])
).project(
scale=1000,
center=[139.883565, 36.565725]
).properties(
width=500,
height=500
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment