Choroplet不绘制任何内容

时间:2019-02-16 17:59:21

标签: python pandas plot plotly

我想使用plotly和Choroplet基于某些国家的人口动态显示世界地图,但它不起作用,我也不明白为什么。

This is my pandas table

该代码应绘制图形:

{{1}}

1 个答案:

答案 0 :(得分:0)

经过几处更改,我终于可以启动您的choropleth:

1。type='choropleth',而不是type='choroplet'

2。'locations',而不是'location'

3。如果您想要世界地图,请将showcoastlines更改为True-这会使地图看起来更漂亮。

4。您可以删除projection中的geo,因为type=equirectangular是此参数的默认值。

我添加了带有默认值的locationmodescope参数(但都注释了)。这些参数应该在构建节律时对您有很大帮助。例如,将scope='world'更改为scope='europe'可以使您仅看到欧洲地图,而不是世界地图(在您的数据中,所有欧洲国家/地区都可以看到)。您可以了解有关这些参数12的更多信息。另外,不要害怕查看有关Choropleth和地理模块34的所有参数的完整参考。

代码:

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

list1 = ['Romania', 'Russia', 'Austria']
list2 = ['ROU', 'RUS', 'AUT']
list3 = [0.4, 0.1, 0.3]

data = [dict(type='choropleth',
             colorscale='Rainbow',
             locations=list2,
             # locationmode='ISO-3',
             z=list3,
             text=list1,
             colorbar=dict(title='Flow of foreign users',
                           titlefont=dict(size=25),
                           tickfont=dict(size=18)),
             )]


layout = dict(title='Flow of foreign users',
              geo=dict(
                       showframe=False,
                       showcountries=True,
                       # scope='world',
                       ),
              )

fig = dict(layout=layout, data=data)
iplot(fig, validate=False, filename='d3-world-map')

输出:

World Map Choropleth