Reputation: 1074
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.
Upvotes: 7
Views: 8985
Reputation: 1
correct method now:
import pygal from pygal_maps_world.maps import World
worldmap = World()
worldmap.title = 'Countries of the World'
worldmap.add('Countries', [('ca', 1), ('us', 1), ('mx', 1)]) # Canada, USA, Mexico
worldmap.render_to_file('countries_map.svg')
Upvotes: 0
Reputation: 1
Import pygal_maps_world.maps
World_map = pygal_maps_world.maps.World()
World_map.title = " Map Of Central Africa"
Then you can continue plotting
Upvotes: 0
Reputation: 1
Both
from pygal.maps.world import World
and
from pygal_maps_world.maps import World
are not working in pycharm the program gets executed without any error but there is no image saved in the file it is empty.
Upvotes: 0
Reputation: 78
You can also use:
from pygal_maps_world.maps import World
wm = World()
if you open pygal_maps_world plugin physically, you will find a maps.py file and inside that file there is a "World" class. So you can reference that particular file by using module_name.file_name, which in this case is pygal_maps_world.maps and then import that class i.e. "World".
Upvotes: 1
Reputation: 22544
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.
Upvotes: 8