Python pygal 代码 - 世界映射

Python pygal code - World mapping

你能帮我看看这段代码吗:

import pygal
from pygal.maps.world import World
worldmap_chart = pygal.maps.world.World()
worldmap_chart.title = 'Some countries'
worldmap_chart.render()

我使用 Spyder。 Python 3.6 。问题是地图没有显示在 IPython 控制台上,而且在代码的第二行,我得到黄色 triangle/note 表示:

'pygal.maps.world.World' imported but unused.

也许这就是地图没有显示的原因。

否则,如果有帮助,在 IPython 控制台中我只会得到:

runfile('C:/Users/Nikki/.spyder-py3/untitled0.py', wdir='C:/Users/Nikki/.spyder-py3')

你能帮我解决这个问题吗?

我个人不怎么用Spyder,不过你的代码第三行好像有错, 你应该试试这个:

import pygal
from pygal.maps.world import World
worldmap_chart = World()
worldmap_chart.title = 'Some countries'
worldmap_chart.render()

或更好:

import pygal
worldmap_chart = pygal.maps.world.World()
worldmap_chart.title = 'Some countries'
worldmap_chart.render()

取决于您需要在 pygalpygal.maps.world 中使用什么。

编辑: 我尝试渲染,但没有出现,一个技巧是在浏览器中渲染,如下所示:

import pygal

worldmap_chart = pygal.maps.world.World()
worldmap_chart.title = 'Some countries'
worldmap_chart.force_uri_protocol= "http"
worldmap_chart.add('North America',{'ca': 84949494949,'mx': 494794164,'us': 99794616})
worldmap_chart.render_in_browser()