Last active
April 13, 2020 10:00
-
-
Save bongole/d9898cbef361b227b100f877a1c72add to your computer and use it in GitHub Desktop.
altair + japan geojson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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