【发布时间】:2023-03-26 15:55:01
【问题描述】:
我有带有 Country 列的用户数据集,并且想绘制一张用户在各个国家/地区的分布图。我将数据集转换为字典,其中键是国家/地区名称,值是国家/地区的频率计数。字典是这样的:
'usa': 139421,
'canada': 21601,
'united kingdom': 18314,
'germany': 17024,
'spain': 13096,
[...]
为了在世界地图上绘制分布,我使用了以下代码:
#Convert to dictionary
counts = users['Country'].value_counts().to_dict()
#Country names
def getList(dict):
return [*dict]
countrs = getList(counts)
#Frequency counts
freqs = list(counts.values())
#Plotting
data = dict(
type = 'choropleth',
colorscale = 'Viridis',
reversescale = True,
locations = countrs,
locationmode = "country names",
z = freqs,
text = users['Country'],
colorbar = {'title' : 'Number of Users'},
)
layout = dict(title = 'Number of Users per Country',
geo = dict(showframe = False)
)
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)
着色错误;它表明所有国家都在0-20K范围内,这是错误的。有没有办法来解决这个问题?谢谢
【问题讨论】:
标签: python plotly choropleth