我试着用Plotly制作印度尼西亚合唱曲,但我仍然对印度尼西亚的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()发布于 2022-08-30 19:24:09
巧妙地将包装成国家和美国的几何图形。如果你想要一个印尼的合唱团,显示不同的地区/省份,你需要提供地理信息。
在这个例子中,我使用了大量的代码,就像使用这个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

发布于 2022-08-30 16:22:32
无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")

https://stackoverflow.com/questions/73539462
复制相似问题