首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >印尼合唱

印尼合唱
EN

Stack Overflow用户
提问于 2022-08-30 08:40:09
回答 2查看 76关注 0票数 1

我试着用Plotly制作印度尼西亚合唱曲,但我仍然对印度尼西亚的locationmodegeo_scope感到困惑。怎么弄明白?

代码语言:javascript
复制
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()
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-08-30 19:24:09

巧妙地将包装成国家和美国的几何图形。如果你想要一个印尼的合唱团,显示不同的地区/省份,你需要提供地理信息。

在这个例子中,我使用了大量的代码,就像使用这个https://github.com/superpikar/indonesia-geojson几何一样。

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2022-08-30 16:22:32

geo_scope

代码语言:javascript
复制
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

代码语言:javascript
复制
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")

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73539462

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档