oneworld.WebMap.add_circles

WebMap.add_circles(latitude, longitude, size=None, color='#592a8a', data=None, sizes=None, palette='Spectral', n_colors=5, cap_min=False, cap_max=False, layer='map', style={'fillOpacity': 0.6, 'opacity': 1.0}, style_mouseover=None, info_mouseover=None, constant_size=False, legend_pos='bottomright', legend_ndec=2, _connect_over=None)

Add circles in specific locations.

Input can be in the form of a pandas dataframe, or in lists or tuples, or a combination of both. The color and the size of each circle can be associated to the value of a variable (set in the color and size parameters). In the case of color, this variable can contain numeric or categorical data. Check out the tutorial.

Parameters:
  • latitude (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in data containing the longitude coordinate for the center of each circle.

  • longitude (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in data containing the latitude coordinate for the center of each circle.

  • size (list or tuple or str or int) – Sequence (list or tuple) or name of the column of the dataframe in data containing the values that will be used to calculate the radius of each circle. Alternatively, it can be a single numerical value, assigning the same radius to all the circles (in pixels if constant_size is True, in meters otherwise) (Default: 1000 for constant_size = False, 10 for constant_size = True).

  • 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 circle. These values can be numeric (float or int) or categorical (str). Alternatively, color can be a hex color that will be applied to all the circles (Default: ‘#592a8a’).

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

  • sizes (list or tuple of 2 elements) – Only relevant if size is not int. Range of sizes to use as radius for the circles (in pixels if constant_size is True, in meters otherwise) (Default: (1000, 10000) if constant_size = False, (1, 20) otherwise).

  • palette (list or tuple or str) – Only relevant when color is not a str corresponding to a hex color. Sequence of hex colors to be used to color the circles according to their value provided in color. Alternatively, palette can be a string with the name of a seaborn color palette (Default: ‘Spectral’).

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

  • cap_min (float or int) – If set, all circles with a numerical value in color smaller than the value set in cap_min will be considered as having a value equal to cap_min for coloring purposes. The corresponding entry in the legend will display a ‘<’ sign. (Default: False).

  • cap_max (float or int) – If set, all circles with a numerical value in color greater than the value set in cap_max will be considered as having a value equal to cap_max for coloring purposes. The corresponding entry in the legend will display a ‘>’ sign. (Default: False).

  • layer (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in data containing the name of the layer on which to draw each circle. Alternatively, it can be the name of a single layer on which all the circles will be added. If the specified layer has not yet been created, oneworld will create an overlay with that name using the default settings (Default: “map”, which will add the circles directly to the map object).

  • style (dict) – Dictionary containing keywords and values defining common style values for all circles. Note that the ‘color’, ‘fillColor’ and ‘radius’ keywords defined in style will override those in the color and size parameters (Default: {‘opacity’:1.0, ‘fillOpacity’:0.6}).

  • style_mouseover (dict) – If set, style of the circles when the mouse is hovered over a circle (Default: None).

  • info_mouseover (list or tuple or str) – If set, sequence (list or tuple) or name of the column of the dataframe in data containing the information to be displayed on a pannel when the mouse is hovered over the circle. Accepts html format (Default: None).

  • constant_size (bool) – If True, circles will have the same size regardless of zoom level (Default: False).

  • legend_pos ({'topleft', 'topright', 'bottomleft', 'bottomright', None}) – Only relevant when color is not a str corresponding to a hex color. Position of the color legend, or None for no legend (Default: “bottomright”).

  • legend_ndec (int) – Only relevant when color is not a str corresponding to a hex color. Number of decimal places to be displayed on the color legend (Default: 2)

Notes

For available color palettes, see https://seaborn.pydata.org/tutorial/color_palettes.html

For a full listing of style options, see https://leafletjs.com/reference-1.6.0.html#path

Examples

To plot the points in the “conferences” dataset using the “Conference” column to color each circle, with a constant size for each circle of 10 pixels regardless of the zoom level we can proceed as follows:

>>> import oneworld as ow
>>> df = ow.load_dataset("conferences")
>>> mymap = ow.WebMap(center = [39,-96.8], zoom = 4)
>>> mymap.add_circles(latitude = 'Lat', longitude = 'Long', data = df,
...                   color = "Conference", size = 10,
...                   constant_size = True)

The resulting map is