API References

Colors countries or specific regions in a country.

worldmap.worldmap.code2county(codes)

Convert abbrevation code to county_name.

Parameters

codes (list of str.) – list containing codes.

Return type

list of str containing county_names.

Examples

>>> NL = wm.code2county('NL')
>>> GB = wm.code2county('GB')
worldmap.worldmap.county2code(county_names)

Convert county_name to abbrevation code.

Parameters

county_names (list of str) – list containing county_names.

Return type

list of str containing abbrevations.

Examples

>>> results = worldmap.county2code('Netherlands')
>>> results = worldmap.county2code('Germany')
worldmap.worldmap.download_resources(url='https://erdogant.github.io/datasets/SVG_MAPS.zip', verbose=3)

Import example dataset from github.

Parameters
Return type

tuple containing import status and resources.

worldmap.worldmap.list_county_names(map_name='world')

Retrieve all county_names.

Parameters

map_name (str, optional) – Name of the country. The default is ‘world’.

Return type

list of county/country names.

Examples

>>> county_names = worldmap.list_county_names(map_name='world')
>>> county_names = worldmap.list_county_names(map_name='netherlands')
>>> county_names = worldmap.list_county_names(map_name='new zealand')
worldmap.worldmap.list_map_names()

Retrieve all map names.

Return type

list of str containing map names.

worldmap.worldmap.plot(county_names, map_name='world', opacity=[], cmap='Set1', filename='custom_map.svg', showfig=True, verbose=True)

Color countries.

Parameters
  • county_names (list of str) – Names of countries or regions within a county to be colored.

  • map_name (str, optional) – Name of the county to be colored. The default is ‘world’.

  • opacity (list of float [0-1], optional) – Set the opacity for each of the map_name(s). The default is []. If values are >1, it is scaled between [0-1] 0 = full transparancy, 1= no transparancy

  • cmap (str, optional) – Colormap to be used. Colors is set on the unique county_names. The default is ‘Set1’. All colormaps can be reverted using the “_r”: e.g., binary_r [‘#ffffff’,’#1f1f1f’]: Each map with a specified color [‘#ff0000’]: All maps have a red color ‘Set1’ : Discrete colors (default) ‘Pastel1’ : Discrete colors ‘Paired’ : Discrete colors ‘bwr’ : Blue-white-red ‘RdBu’ : Red-white-Blue ‘binary’ : black-white ‘seismic’ : Blue-white-red ‘rainbow’ : all coors ‘Blues’ : white-to-blue

  • filename (str, optional) – filepath to write the output file. The default is ‘custom_map.svg’.

  • showfig (bool, optional) – Open figure in browser. The default is False.

  • verbose (int, optional) – print message to screen. The default is True.

Returns

Containing dataframe with the plotted regions, with its colors and the filename.

Return type

tuple (pd.DataFrame, filename)

Examples

>>> # Import library
>>> import worldmap as wm
>>>
>>> # Set the regions to plot
>>> region = ['zeeland','Overijssel', 'flevoland']
>>>
>>> # Color the regions
>>> opacity = [0.1, 0.2, 0.6]
>>>
>>> # Create the SVG
>>> results = wm.plot(region, opacity=opacity, cmap='Set1', map_name='netherlands')