def birth_rate(): # Create a chart object of 200x100 pixels chart = MapChart(440, 220) # Load the data from a file, create a dict that looks like: # {'AU': 5, 'YE': 10} data = {} countries = open('mapchart-birth-rate.txt', 'rb').read().split('\n') for line in countries[:-1]: code, score = line.split(' ', 1) data[code] = float(score) # Set the data dictionary for country codes to value mapping chart.add_data_dict(data) # Download the chart chart.download('mapchart-birth-rate.png') # Now do it in africa ... chart.set_geo_area('africa') # ... with white as the default colour and gradient from green to red chart.set_colours(('EEEEEE', '10A010', 'D03000')) chart.download('mapchart-birth-rate-africa.png')
states['all'][state] = states['all'].get(state, 0) + quarter countries[tel][country] = countries[tel].get(country, 0) + quarter countries['all'][country] = countries['all'].get(country, 0) + quarter # write data to file country_file = open('projects_countries_' + mode + '.csv', 'w') country_file.write('tel,iso_country,q4\n') country_writer = csv.writer(country_file) for tel in telescopes: for country in country_list: country_writer.writerow([tel, country, '%.02f' % countries[tel][country]]) # Now for the experimental chart generation. all_countries = copy.deepcopy(countries['all']) all_countries.pop('') chart = MapChart(440, 220) chart.set_colours(('FFFFFF', 'CCCCCC', '000000')) chart.set_codes(all_countries.keys()) chart.add_data(all_countries.values()) chart.download('projects_countries_all_telescopes_' + mode + '.png') all_countries.pop('US') chart = MapChart(440, 220) chart.set_colours(('FFFFFF', 'CCCCCC', '000000')) chart.set_codes(all_countries.keys()) chart.add_data(all_countries.values()) chart.download('projects_countries_foreign_all_telescopes_' + mode +'.png')