我正在尝试使用plotly.js
在地图上绘制数据。我知道你可以通过以下方式获得一个国家的地图:
layout = dict(
title = '',
geo = dict(
scope='usa',
...
)
我们是否有可用范围列表,即不同地区,某些地区?我试过谷歌搜索但似乎无法找到它。在这个例子中他们也有'非洲',但其他地方呢?
答案 0 :(得分:6)
来自documentation :
范围(枚举:"世界" |"美国" |"欧洲" |"亚洲" |"非洲&#34 ;"北美" |"南美洲") 默认:"世界"
答案 1 :(得分: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()