Plotly中所有地理范围的列表

7
我将尝试使用plotly.js在地图上绘制数据。我知道你可以从以下位置获得一个国家的地图:
layout = dict(
        title = '',
        geo = dict(
            scope='usa',
            ...
             )

我们是否有可用范围的列表,例如不同地区的一些地方?我尝试过谷歌搜索,但似乎找不到。在示例中,他们也有“非洲”,但其他地方呢?

2个回答

20

来自文档:

范围(枚举:"world" | "usa" | "europe" | "asia" | "africa" | "north america" | "south america")默认值:"world"


11
有没有办法限制地图只显示一个或几个美国州?如何让地图仅显示一个州?或者说是否可以在开始时自动进行缩放。 - Rotail
3
如果您添加fig.update_geos(fitbounds="locations"),它将缩放到当前数据。请参见https://plotly.com/python/map-configuration/#automatic-zooming-or-bounds-fitting中的“自动缩放或边界拟合”。 - newmathwhodis

1

您可以使用 create_choropleth,详见文档 https://plotly.com/python/county-choropleth/

以下是一个示例:

import plotly.figure_factory as ff
import numpy as np
import pandas as pd


'''
 By default scope is set to ['USA']
which the API treats as identical to passing a list of all 50 state names:
['AK', 'AL', 'CA', ...]
'''
df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv')
df_sample_r = df_sample[df_sample['STNAME'] == 'California']

values = df_sample_r['TOT_POP'].tolist()
fips = df_sample_r['FIPS'].tolist()

colorscale = [
    'rgb(193, 193, 193)',
    'rgb(239,239,239)',
    'rgb(195, 196, 222)',
    'rgb(144,148,194)',
    'rgb(101,104,168)',
    'rgb(65, 53, 132)'
]

fig = ff.create_choropleth(
    fips=fips, values=values, scope=['CA', 'AZ', 'Nevada', 'Oregon', ' Idaho'],
    binning_endpoints=[14348, 63983, 134827, 426762, 2081313], colorscale=colorscale,
    county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, round_legend_values=True,
    legend_title='Population by County', title='California and Nearby States'
)
fig.layout.template = None
fig.show()



1
虽然这个链接可能回答了问题,但最好在此处包含答案的基本部分并提供参考链接。仅有链接的答案如果链接页面发生更改可能会变得无效。 - Matt Ke
好的链接,你应该像Matt建议的那样在这里发布一个示例。 - RichieV

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接