色度图未显示颜色

时间:2020-07-18 23:00:26

标签: python numpy dataframe matplotlib geopandas

我有一个数据集
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)

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

谢谢!

1 个答案:

答案 0 :(得分:0)

我尝试复制您的数据,发现您缺少一个重要参数,即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)