コード例 #1
0
class PWorldMap(object):
    '''
    classdocs
    '''
    def __init__(self, title):
        '''
        Constructor
        '''
        self.wmap = World()
        self.wmap.title = title

    def sample(self):
        self.wmap.add('F countries', ['fr', 'fi'])
        self.wmap.add('M countries', [
            'ma', 'mc', 'md', 'me', 'mg', 'mk', 'ml', 'mm', 'mn', 'mo', 'mr',
            'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz'
        ])
        self.wmap.add('U countries', ['ua', 'ug', 'us', 'uy', 'uz'])
        self.wmap.add('North America', {
            'ca': 84949494949,
            'mx': 494794164,
            'us': 99794616
        })

    def render(self, filename=None):
        '''
        render the map
        see http://www.pygal.org/en/stable/documentation/output.html
        '''
        if filename is None:
            self.wmap.render_in_browser()
        else:
            if filename.endswith(".png"):
                self.wmap.render_to_png(filename)
            else:
                self.wmap.render_to_file(filename)
コード例 #2
0
from pygal_maps_world.maps import World
from pygal.style import Style

style = Style(font_family='googlefont:Raleway')

blue = Style(colors=('blue', ))
worldmap_chart = World(style=blue)
worldmap_chart.title = 'Country of residence'
worldmap_chart.add(
    'Students', {
        'by': 1,
        'ca': 1,
        'ch': 1,
        'cn': 1,
        'de': 4,
        'eg': 1,
        'in': 11,
        'kr': 1,
        'ru': 1,
        'sg': 1,
        'us': 4,
        'gr': 1
    })
worldmap_chart.render_to_png("./world.png")