def paint(stats, seed_name):

    print 'Printing graphs...'

    country_dict = dict()

    try:
        for key in stats['country']:
            country_dict[key.lower()] = stats['country'][key]

        world_chart = pygal.Worldmap(width=1080, style=custom_style)
        world_chart.title = 'Malicious server by country'
        world_chart.add('Infected countries', country_dict)
        world_chart.render_to_file('{}_wm.svg'.format(seed_name))
    except Exception as err:
        print "An error ocurred: {}".format(err)
        sys.exit()
    print 'Worldmap generated at: {}'.format('{}_wm.svg'.format(seed_name))

    try:
        bar_chart = pygal.Bar(style=custom_style)
        bar_chart.title = 'Crimeserver endurance (in hours)'
        for x in serv_type:
            bar_chart.add(x, stats['top_ip_' + x])
        bar_chart.render_to_file('{}_bar.svg'.format(seed_name))
    except Exception as err:
        print "An error ocurred: {}".format(err)
        sys.exit()
    print 'Bar graph generated at: {}'.format('{}_bar.svg'.format(seed_name))
Example #2
0
def generate_worldmap(data):
    """ Generates a worldmap-svg to display the distribution of worldwide tor-usage
        very human-readable.
    """
    wm = pygal.Worldmap(width=300, height=200, show_legend=False, margin=0, style=TorcollectStyle())
    wm.add('Tor Usage', data)
    return clean_graph(wm.render())
Example #3
0
def plot(locate):
    wm = pygal.Worldmap()
    wm.title = 'Gdp of 2016'
    wm.add('2016', locate)
    wm_style = RS('#336699', base_style=LCS)

    wm.render_to_file('gdp_2016.svg')
Example #4
0
def draw_unemployment():
    imf_data = load_and_merge_data()
    worldmap_data = {}
    for row in imf_data:
        worldmap_data[row.get('iso').lower()] = float(row.get('2015'))
    worldmap_chart = pygal.Worldmap()
    worldmap_chart.title = '2015 Unemployment'
    worldmap_chart.add('Total Unemployment (%)', worldmap_data)
    worldmap_chart.render()
Example #5
0
def country_map(ccode):
    country = COUNTRY[ccode]
    print country,ccode
    temperature = country_temp(country)
    print temperature
    worldmap_chart = pygal.Worldmap()
    worldmap_chart.title = 'Country heat map (updates every one hour)'
    worldmap_chart.add('Select Country', {
                                ccode.lower() : int(temperature)
                            }
                    )
    return Response(response=worldmap_chart.render(), content_type='image/svg+xml')
def plot(year, pop1, pop2='', pop3=''):
    wm_style = RS('#336655')
    wm = pygal.Worldmap(style=wm_style)
    wm.title = 'Population of The World'

    if pop2 and pop3:
        wm.add('0-10m', pop1)
        wm.add('10m-1bn', pop2)
        wm.add('>1bn', pop3)

    else:
        wm.add(year, pop1)

    wm.render_to_file("World Population %s.svg" % year)
Example #7
0
# -*- coding: utf-8 -*-
import pygal

worldmap_chart = pygal.Worldmap()
worldmap_chart.title = 'United States Allies and China'
worldmap_chart.add('China', ['cn'])
worldmap_chart.add('U.S. Allies', ['al',
'be','bg','ca','hr','cz','dk','ee','ff','de','hu','is','it',
'lv','lt','lu','nl','no','pl','pt','ro','si','sk','tr','us','uk'])

#Render file.
worldmap_chart.render_to_file('world_map.svg')
Example #8
0
def export_map(data, title, filename):
    worldmap_chart = pygal.Worldmap(legend_at_bottom=True)
    worldmap_chart.title = title
    for row in data:
        worldmap_chart.add(row[0], row[1])
    saveChart(worldmap_chart, filename)
Example #9
0
cc_populations = {}
#打印每个国家2010年的人口数量
#json的数据是一个由字典组成的序列
for pop_dict in pop_date:
    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

cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
for cc, pop in cc_populations.items():
    if pop < 10000000:
        cc_pops_1[cc] = pop
    elif pop < 1000000000:
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop
#查看每组有多少个国家
print(len(cc_pops_1), len(cc_pops_2), len(cc_pops_3))
wm_style = RedBlueStyle

wm = pygal.Worldmap(style=wm_style)
wm.title = 'world population in 2010,by country'

wm.add('0-10m', cc_pops_1)
wm.add('10m-1bn', cc_pops_2)
wm.add('>1bn', cc_pops_3)

wm.render_to_file('world_population.svg')
Example #10
0
import pygal

wm = pygal.Worldmap()
wm.title = 'Population of Countries in North Amercia'
wm.add('North Amercia', {'ca': 3412600, 'us': 309349000, 'mx': 113423000})
wm.render_to_file('na_populations.svg')
Example #11
0
# Program generare grafic pygal
# Explica functiile pygal
# Ion Studentul - 1/26/13

import pygal

bar_chart = pygal.Worldmap()
bar_chart.fill = True
bar_chart.no_data_text = "Fara Date"
bar_chart.title = 'Locatie: Bucuresti'
bar_chart.human_readable = True
bar_chart.y_title = 'Elemente masurate'
bar_chart.x_title = 'Timp'
bar_chart.render()
bar_chart.add('Bandwindth Voce-Mbps', [5, 7, 1, 0, 8, 12, 3, 8, 13, 20, 24])
bar_chart.add('Bandwindth Date-Mbp', [4, 10, 5, 0, 4, 20, 8, 13, 21, 34, 55])
bar_chart.render_to_file('grafic6.svg')

raw_input("\n\nApasa <enter> pt a iesi.")
Example #12
0
        temp = numpy.array(df2[df2.geoname == ct])[0,1::]
        # replace 'in_country' by 'in_continent' if in the list 'geo_go_by_continent'
        if ct.lower() in geo_go_by_continent:
            temp[2] = temp[3]
            temp[6] = temp[7]

        hex_colors = '#%0.2x' % (255 * (1-numpy.exp(-1*temp[0]/Tscale))) + '%0.2x' % (255 * (1-numpy.exp(-1*temp[1]/Tscale))) + '%0.2x' % (255 * (1-numpy.exp(-1*temp[2]/Tscale)))
        color_set = color_set + "'%s'," % hex_colors

    cmd_str = "custom_style = Style( colors=(%s) )" % color_set[0:len(color_set)-1]
    from pygal.style import Style
    exec(cmd_str)
    if int((pygal.__version__)[0]) > 1:
        worldmap = pygal.maps.world.World(show_legend=False, style=custom_style)
    else:
        worldmap = pygal.Worldmap(show_legend=False, style=custom_style)
    worldmap.title = 'Maprule '+str(mrid)

    # measurement type temp string:
    Score_str = ''
    Distance_str = ''
    OutGeo_str = ''
    # add the categorical data for later plots
    for ct in geo_data:
        temp = numpy.array(df2[df2.geoname == ct])[0,1::]
        # replace 'in_country' by 'in_continent' if in the list 'geo_go_by_continent'
        if ct.lower() in geo_go_by_continent:
            temp[2] = temp[3]
            temp[6] = temp[7]
        Score_str = Score_str + "{'value': ('" + ct.lower() + "', " + str(temp[0]) + ")},";
        Distance_str = Distance_str + "{'value': ('" + ct.lower() + "', " + str(temp[1]) + ")},";
Example #13
0
def plot(popl):
    wm = pygal.Worldmap()
    wm.title = 'Population of Countries in North Amercia'
    wm.add('2010', popl)
    wm.render_to_file('World Population 2009.svg')