Choropleth贴图不显示颜色

2024-10-02 18:23:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据集
enter image description here

data2 = dict(type = 'choropleth',
           locations = df3['Code'],
           z = df3['Power Consumption KWH'])
layout2 = dict(title = '2014 Global Power Consumption',
             geo = dict(showframe = False, projection = {'type': 'natural earth'}))

choromap2 = go.Figure(data = [data2], layout=layout2)
iplot(choromap2)

在那之后,我创建了一个choropleth,但我的问题是地图没有显示任何颜色,它只显示了地球的形状。
enter image description here

提前谢谢


Tags: 数据titletypecodeglobaldictkwhpower
1条回答
网友
1楼 · 发布于 2024-10-02 18:23:18

我试图复制您的数据,发现您缺少一个重要参数,即locationmode = "country names"。加上这个应该行得通

data2 = dict(type = 'choropleth',
           locations = df['Code'],
            locationmode = "country names", # add this 
           z = df['Power Consumption KWH'])
layout2 = dict(title = '2014 Global Power Consumption',
             geo = dict(showframe = False, projection = {'type': 'natural earth'}))

choromap2 = go.Figure(data = [data2], layout=layout2)
iplot(choromap2)

相关问题 更多 >