Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import pygal_maps_world.World

I am trying to create a simple program so as to display the map of Central America with its population using Pygal_maps_world. Here's the code for the same:

import pygal_maps_world as pa

wm=pa.World()

wm.title="Map of Central America"
wm.add('North America',{'cd': 84949494949,'mx': 494794164,'us': 99794616})

wm.render_to_file('map.svg')

I have tried a few combinations regarding the importing of the World maps to work properly but to no avail and I am not able to create the visualization.

like image 917
Dhruv Marwha Avatar asked Jun 07 '16 12:06

Dhruv Marwha


Video Answer


1 Answers

In the recent versions of pygal, you start with the first four lines of this code:

from pygal.maps.world import World

wm = World()
wm.force_uri_protocol = 'http'

wm.title="Map of Central America"
wm.add('North America',{'ca': 84949494949,'mx': 494794164,'us': 99794616})

wm.render_to_file('map.svg')

When I use those first four lines and the rest of your code, your code runs and it highlights the United States and Mexico, but it highlights the Democratic Republic of the Congo rather than Canada. Change the country code to 'ca' for Canada! This then, of course, now shows North America rather than central America, so either change your title or change your country codes.

enter image description here

like image 175
Rory Daulton Avatar answered Oct 05 '22 23:10

Rory Daulton