def __init__(self, data=None, geo_data=None, projection="winkel3",
                 center=None, translate=None, scale=None, rotate=None,
                 data_bind=None, data_key=None, map_key=None,
                 brew='GnBu', *args, **kwargs):
        """Create a Vega Map. Takes standard Chart class parameters.

        Note: Data binding only works with Pandas DataFrames right now.

        `geo_data` needs to be passed as a list of dicts with the following
        format:
        {
            name: data name
            url: path_to_data,
            feature: TopoJSON object set (ex: 'countries')
        }

        Parameters
        ----------
        data: Tuples, List, Dict, Pandas Series, or Pandas DataFrame
            Input data. Tuple of paired tuples, List of single values,
            dict of key/value pairs, Pandas Series/DataFrame, Numpy ndarray.
            Used to bind to map for choropleth mapping.
        geo_data: list, default None
            List of dicts
        projection: string, default "winkel3"
            Map projection
        center: list, default None
            Two element list with projection center
        translate: list, default None
            Two element list with projection translation
        scale: integer, default None
            Projection scale
        rotate: integer, default None
            Projection rotation
        data_bind:str, default None
            Column you want to visualize. E.g. the data value you are binding
            to the map
        data_key: str, default None
            If passing data to bind to the map, data field to key-on. For a
            Pandas DataFrame, this would be the column name.
        map_key: dict, default None
            Key: The geo-data you are keying to. Value: The map property that
            you are keying your data on. This can be nested with dot notation.
            Ex: 'properties.name'
        brew: str, default GnBu
            Color brewer abbreviation. See colors.py

        Returns
        -------
        Vega Chart

        """

        self.raw_data = data
        self.data_key = data_key

        super(Map, self).__init__(no_data=True, *args, **kwargs)

        # Don't want to pass None to property setters
        geo_kwargs = {}
        for param in [('projection', projection), ('center', center),
                      ('translate', translate), ('scale', scale),
                      ('rotate', rotate)]:
            if param[1]:
                geo_kwargs[param[0]] = param[1]

        if not translate:
            geo_kwargs['translate'] = [self.width/2, self.height/2]

        # Add Data
        for dat in geo_data:
            # Data
            transforms = []
            if data is not None and list(map_key.keys())[0] == dat['name']:
                get_brewer = True
                if not data_key or not data_bind:
                    raise ValueError('If passing data, '
                                     'you must pass data cols to key/bind on')
                self.data['table'] = Data.keypairs(
                    data, columns=[data_key, data_bind]
                    )
                key_join = '.'.join(['data', map_key[dat['name']]])
                data_transform = Transform(
                    type='zip', key=key_join, with_='table',
                    with_key='data.x', as_='value', default='noval'
                    )
                transforms.append(data_transform)
                null_trans = Transform(
                    type='filter', test="d.path!='noval' && d.value!='noval'"
                    )
                transforms.append(null_trans)
            else:
                get_brewer = False

            geo_transform = Transform(
                type='geopath', value="data", **geo_kwargs
                )
            transforms.append(geo_transform)
            self.data[dat['name']] = Data(
                name=dat['name'], url=dat['url'], transform=transforms
                )
            if dat.get('feature'):
                self.data[dat['name']].format = {
                    'type': "topojson",
                    'feature': dat['feature']
                    }

            # Marks

            geo_from = MarkRef(data=dat['name'])

            enter_props = PropertySet(
                stroke=ValueRef(value='#000000'),
                path=ValueRef(field='path')
                )

            if get_brewer:
                update_props = PropertySet(
                    fill=ValueRef(scale='color', field='value.data.y')
                    )
                domain = [Data.serialize(data[data_bind].min()),
                          Data.serialize(data[data_bind].quantile(0.95))]
                scale = Scale(name='color', type='quantize', domain=domain,
                              range=brews[brew])
                self.scales['color'] = scale
            else:
                update_props = PropertySet(fill=ValueRef(value='steelblue'))

            mark_props = MarkProperties(enter=enter_props, update=update_props)

            self.marks.append(
                Mark(type='path', from_=geo_from, properties=mark_props)
                )
def __init__ ( self , data = None , geo_data = None , projection = "winkel3" , center = None , translate = None , scale = None , rotate = None , data_bind = None , data_key = None , map_key = None , brew = 'GnBu' , * args , ** kwargs ) : self . raw_data = data self . data_key = data_key super ( Map , self ) . __init__ ( no_data = True , * args , ** kwargs ) geo_kwargs = { } for param in [ ( 'projection' , projection ) , ( 'center' , center ) , ( 'translate' , translate ) , ( 'scale' , scale ) , ( 'rotate' , rotate ) ] : if param [ 1 ] : geo_kwargs [ param [ 0 ] ] = param [ 1 ] if not translate : geo_kwargs [ 'translate' ] = [ self . width / 2 , self . height / 2 ] for dat in geo_data : transforms = [ ] if data is not None and list ( map_key . keys ( ) ) [ 0 ] == dat [ 'name' ] : get_brewer = True if not data_key or not data_bind : raise ValueError ( 'If passing data, ' 'you must pass data cols to key/bind on' ) self . data [ 'table' ] = Data . keypairs ( data , columns = [ data_key , data_bind ] ) key_join = '.' . join ( [ 'data' , map_key [ dat [ 'name' ] ] ] ) data_transform = Transform ( type = 'zip' , key = key_join , with_ = 'table' , with_key = 'data.x' , as_ = 'value' , default = 'noval' ) transforms . append ( data_transform ) null_trans = Transform ( type = 'filter' , test = "d.path!='noval' && d.value!='noval'" ) transforms . append ( null_trans ) else : get_brewer = False geo_transform = Transform ( type = 'geopath' , value = "data" , ** geo_kwargs ) transforms . append ( geo_transform ) self . data [ dat [ 'name' ] ] = Data ( name = dat [ 'name' ] , url = dat [ 'url' ] , transform = transforms ) if dat . get ( 'feature' ) : self . data [ dat [ 'name' ] ] . format = { 'type' : "topojson" , 'feature' : dat [ 'feature' ] } geo_from = MarkRef ( data = dat [ 'name' ] ) enter_props = PropertySet ( stroke = ValueRef ( value = '#000000' ) , path = ValueRef ( field = 'path' ) ) if get_brewer : update_props = PropertySet ( fill = ValueRef ( scale = 'color' , field = 'value.data.y' ) ) domain = [ Data . serialize ( data [ data_bind ] . min ( ) ) , Data . serialize ( data [ data_bind ] . quantile ( 0.95 ) ) ] scale = Scale ( name = 'color' , type = 'quantize' , domain = domain , range = brews [ brew ] ) self . scales [ 'color' ] = scale else : update_props = PropertySet ( fill = ValueRef ( value = 'steelblue' ) ) mark_props = MarkProperties ( enter = enter_props , update = update_props ) self . marks . append ( Mark ( type = 'path' , from_ = geo_from , properties = mark_props ) )
Create a Vega Map. Takes standard Chart class parameters.

        Note: Data binding only works with Pandas DataFrames right now.

        `geo_data` needs to be passed as a list of dicts with the following
        format:
        {
            name: data name
            url: path_to_data,
            feature: TopoJSON object set (ex: 'countries')
        }

        Parameters
        ----------
        data: Tuples, List, Dict, Pandas Series, or Pandas DataFrame
            Input data. Tuple of paired tuples, List of single values,
            dict of key/value pairs, Pandas Series/DataFrame, Numpy ndarray.
            Used to bind to map for choropleth mapping.
        geo_data: list, default None
            List of dicts
        projection: string, default "winkel3"
            Map projection
        center: list, default None
            Two element list with projection center
        translate: list, default None
            Two element list with projection translation
        scale: integer, default None
            Projection scale
        rotate: integer, default None
            Projection rotation
        data_bind:str, default None
            Column you want to visualize. E.g. the data value you are binding
            to the map
        data_key: str, default None
            If passing data to bind to the map, data field to key-on. For a
            Pandas DataFrame, this would be the column name.
        map_key: dict, default None
            Key: The geo-data you are keying to. Value: The map property that
            you are keying your data on. This can be nested with dot notation.
            Ex: 'properties.name'
        brew: str, default GnBu
            Color brewer abbreviation. See colors.py

        Returns
        -------
        Vega Chart