Visualization world map with pygal - No data

0

I'm with the book Python Crash Course and I can not visualize the World population map. When I open the .svg file in Chrome I receive the error of 'No Data'.

I do not receive any errors when I run the program. Printing the cc_populations dictionary is printed correctly, so the information is actually stored.

Thanks in advance!

The code is as follows:

import json
import pygal
from country_codes import get_country_code
from pygal.maps.world import World

wm = World()


filename = 'population_data.json'

with open(filename) as f:
    pop_data = json.load(f)

# Print each country's population

cc_populations = {}

for pop_dict in pop_data:
    if pop_dict['Year'] == '2010':
        country_name = pop_dict['Country Name']
        population = int(float((pop_dict['Value'])))
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population

# Create map
wm.title = 'World population in 2010 per country'
wm.add = ('2010', cc_populations)
wm.render_to_file('world_population.svg')

print(cc_populations)
    
asked by Johnny 24.09.2018 в 13:03
source

1 answer

0

I have already discovered the fault.

I was not adding the data correctly:

wm.add = ('2010', cc_populations)

should be

wm.add('2010', cc_populations)
    
answered by 27.09.2018 в 11:34