印度尼西亚地区分布图

问题描述 投票:0回答:3

我正在尝试使用 Plotly 制作 Choropleth Indonesia,但我仍然对印度尼西亚的

locationmode
geo_scope
感到困惑。怎么算出来的?

fig8 = go.Figure(data=go.Choropleth(
    locations=df['Column'], # Spatial coordinates
    z = df['Columnnext'], # Data to be color-coded
    locationmode = 'ISO-3', # set of locations match entries in `locations`
    colorscale = 'Reds',
    colorbar_title = "Column",
))

fig8.update_layout(
    title_text = 'Title Bla Bla Bla',
    geo_scope='asia',
)

fig8.show()
python plotly choropleth
3个回答
1
投票

plotly 包含国家和美国各州的几何图形。如果您想要显示印度尼西亚不同地区/省份的地区统计图,您需要提供 geojson

在这个例子中,我几乎使用了你的代码,使用这个https://github.com/superpikar/indonesia-geojson几何。

import requests
import pandas as pd
import plotly.graph_objects as go

# indonesia geojson
geojson = requests.get(
    "https://raw.githubusercontent.com/superpikar/indonesia-geojson/master/indonesia-province-simple.json"
).json()

# dataframe with columns referenced in question
df = pd.DataFrame(
    {"Column": pd.json_normalize(geojson["features"])["properties.Propinsi"]}
).assign(Columnnext=lambda d: d["Column"].str.len())

fig8 = go.Figure(
    data=go.Choropleth(
        geojson=geojson,
        locations=df["Column"],  # Spatial coordinates
        featureidkey="properties.Propinsi",
        z=df["Columnnext"],  # Data to be color-coded
        colorscale="Reds",
        colorbar_title="Column",
    )
)
fig8.update_geos(fitbounds="locations", visible=False)

fig8


1
投票

没有

geo_scope

import plotly.graph_objects as go

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')

fig = go.Figure(data=go.Choropleth(
    locations=df['code'], # Spatial coordinates
    z = df['total exports'].astype(float), # Data to be color-coded
    locationmode = 'USA-states', # set of locations match entries in `locations`
    colorscale = 'Reds',
    colorbar_title = "Millions USD",
))

fig.update_layout(
    title_text = '2011 US Agriculture Exports by State',
    # geo_scope='usa', # limite map scope to USA
)

fig.show()

geo_scope

import plotly.graph_objects as go

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')

fig = go.Figure(data=go.Choropleth(
    locations=df['code'], # Spatial coordinates
    z = df['total exports'].astype(float), # Data to be color-coded
    locationmode = 'USA-states', # set of locations match entries in `locations`
    colorscale = 'Reds',
    colorbar_title = "Millions USD",
))

fig.update_layout(
    title_text = '2011 US Agriculture Exports by State',
    geo_scope='usa', # limite map scope to USA
)

fig.show("browser")


0
投票

我喜欢印尼方式https://indonesian-online.com。这是迄今为止学习印度尼西亚语的最佳工具,而且他们还提供免费课程。相信,这是货真价实的。

© www.soinside.com 2019 - 2024. All rights reserved.