oneworld.StaticMap.add_choropleth

StaticMap.add_choropleth(shp_file, geoid, color, data=None, shp_key='GEOID', crs='PlateCarree', palette='YlOrRd', n_colors=10, cap_max=False, cap_min=False, legend_show=True, legend_pos='lower center', legend_orient='vertical', legend_ndec=2, **kwargs)

Add a choropleth to the map.

Polygons representing areas must be supplied via a shapefile. Colors of polygons can be specified using a sequence containing the values to be used to determine color or a dataframe. For each value in color there should be a value in geoid, which will be used to identidfy the corresponding polygon in the shapefile. The algorithm will look for such values in the shp_key attribute of the shapefile.

Parameters:
  • shp_file (str) – Full path name of the shapefile.

  • geoid (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in data containing the string that will be used to identify each polygon on the shp_file.

  • color (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in data containing the values that will be used to determine the color of each polygon. These values can be numeric (float or int) or categorical (str).

  • data (pandas DataFrame) – Dataframe containing one or more columns of values to use. Each row must contain the data for a polygon, with columns as the data to be used (Default: None).

  • shp_key (str) – Name of the attribute that will be used to identify each polygon (Default: “GEOID”).

  • palette (list or tuple or str) – Sequence of hex colors to be used to color the polygons according to their value provided in color. Alternatively, palette can be a string with the name of a seaborn color palette https://seaborn.pydata.org/tutorial/color_palettes.html (Default: ‘Spectral’).

  • n_colors (int) – Number of colors in the specified seaborn palette (Default: 5).

  • cap_min (float or int) – If set, all numerical values less than this value will have the same color. Ignored for categorical data (Default: False).

  • cap_max (float or int) – If set, all numerical values greater than this value will have the same color. Ignored for categorical data (Default: False).

  • legend_show (bool) – If True, display a color legend (Default: True).

  • legend_pos ({'best', 'upper right', 'upper left', 'lower left', 'lower right', 'right', 'center left', 'center right', 'lower center', 'upper center', 'center'} or) – list or tuple Position of the colorbar. Can be one of the predefined positions, or a list or tuple of figure relative coordinates (x, y, width, height) Only relevant when legend_show is True. (Default: ‘lower center’).

  • legend_orient ({'horizontal', 'vertical'}) – Only relevant when legend_pos is a list or tuple containing coordinates and dimensions of the colorbar. Orientation of the colorbar (Default: ‘vertical’)

  • legend_ndec (int) – Only relevant when legend_show is True. Number of decimal places to be displayed on the legend (Default: 2).

  • crs (str) – Coordinate reference system on which polygon geometries are specified. See https://scitools.org.uk/cartopy/docs/latest/crs/index.html for a full list of supported crs (Default: ‘PlateCarree’).

  • **kwargs – Extra arguments for the plotting function.

See also

add_shp