oneworld.WebMap.add_network

WebMap.add_network(latitude, longitude, source=None, target=None, group_connect=None, node_data=None, edge_data=None, connect_mouseover=None, node_kwargs={}, edge_kwargs={})

Add nodes connected by edges.

Nodes will be depicted as circles, connected by lines (edges). For the nodes, input can be in the form of a pandas dataframe, or in lists or tuples, or a combination of both. Connectivity between nodes can be specified either by the source and target parameters, or using the group_connect parameter. In the latter case, oneworld will fully connect all nodes that have the same value in the group_connect parameter.

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

  • longitude (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in node_data containing the latitude coordinate for the center of a node.

  • source (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in edge_data where each element contains the index of the source node of one edge (Default: None).

  • target (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in edge_data where each element contains the index of the target node of one edge (Default: None).

  • group_connect (list or tuple or str) – Sequence (list or tuple) or name of the column of the dataframe in node_data containing the values that will be used to group the nodes in fully connected components in the network (Default: None)

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

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

  • connect_mouseover (list or tuple of two dicts) – If set, the first dict specifies the style of the neighboring nodes when a given node is hovered by the mouse. The second dict defines the styles of the edges connecting the hovered node with its neighbors (Default: None).

  • node_kwargs (dict) – Dictionary containing extra parameters to pass to the add_circles method. If node_data is provided, it will be passed automatically as the data parameter to the add_circles method (Default: {}).

  • edge_kwargs (dict) – Dictionary containing extra parameters to pass to the add_lines method. If edge_data is provided, it will be passed automatically as the data parameter to the add_lines method (Default: {}).

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

For a dataframe df containing the latitudes and longitudes of nodes in columns ‘Lat’ and ‘Long’ respectively, to connect nodes 2 and 3, nodes 2 and 5 and nodes 5 and 8 we would

>>> import oneworld as ow
>>> df = ow.load_dataset("conferences")
>>> mymap = ow.WebMap(center = [39,-96.8], zoom = 4)
>>> mymap.add_network(latitude = 'Lat', longitude = 'Long',
...                   node_data = df,
...                   source = [2, 2, 5], target = [3, 5, 8])

If instead we want to connect all the nodes that have the same value on column ‘Conference’ of the dataframe and color nodes and edges accordingly we can write:

>>> mymap.add_network(latitude = 'Lat', longitude = 'Long',
...                   node_data = df, group_connect = 'Conference')