I’m trying to make Choropleth Indonesia using Plotly, but I still confused about locationmode
and geo_scope
of Indonesia. How to figure it out?
JavaScript
x
15
15
1
fig8 = go.Figure(data=go.Choropleth(
2
locations=df['Column'], # Spatial coordinates
3
z = df['Columnnext'], # Data to be color-coded
4
locationmode = 'ISO-3', # set of locations match entries in `locations`
5
colorscale = 'Reds',
6
colorbar_title = "Column",
7
))
8
9
fig8.update_layout(
10
title_text = 'Title Bla Bla Bla',
11
geo_scope='asia',
12
)
13
14
fig8.show()
15
Advertisement
Answer
plotly is packaged with country and US state geometry. If you want to have a choropleth of Indonesia showing different regions / provinces you need to supply the geojson
In this example I have pretty much used you code as as, using this https://github.com/superpikar/indonesia-geojson geometry.
JavaScript
1
28
28
1
import requests
2
import pandas as pd
3
import plotly.graph_objects as go
4
5
# indonesia geojson
6
geojson = requests.get(
7
"https://raw.githubusercontent.com/superpikar/indonesia-geojson/master/indonesia-province-simple.json"
8
).json()
9
10
# dataframe with columns referenced in question
11
df = pd.DataFrame(
12
{"Column": pd.json_normalize(geojson["features"])["properties.Propinsi"]}
13
).assign(Columnnext=lambda d: d["Column"].str.len())
14
15
fig8 = go.Figure(
16
data=go.Choropleth(
17
geojson=geojson,
18
locations=df["Column"], # Spatial coordinates
19
featureidkey="properties.Propinsi",
20
z=df["Columnnext"], # Data to be color-coded
21
colorscale="Reds",
22
colorbar_title="Column",
23
)
24
)
25
fig8.update_geos(fitbounds="locations", visible=False)
26
27
fig8
28