Network

class visigoth.map_layers.network.Network(node_data, edge_data, node_id=0, node_lon=1, node_lat=2, node_label=None, node_size=None, edge_from_node=0, edge_to_node=1, ranking_algorithm=None, palette=None, marker_manager=None, font_height=8, text_attributes={})
Create a Network plot
node_data (list): A relational data set (for example, list of dicts/lists/tuples describing each node) edge_data (list): A relational data set (for example, list of dicts/lists/tuples describing each edge)
Keyword Arguments:
 
  • node_id (str or int) – Identify the column to provide the id value for each node
  • node_lon (str or int) – Identify the column to provide the longitude value for each node
  • node_lat (str or int) – Identify the column to provide the latitude value for each node
  • node_label (str or int) – Identify the column to provide the label for each node
  • node_size (str or int) – Identify the column to provide the size for each node
  • edge_from_node (str or int) – Identify the column to provide the id of the origin node for each edge
  • edge_to_node (str or int) – Identify the column to provide the id of the destination node for each edge
  • ranking_algorithm (object) – to colour nodes by rank, pass an instance of visigoth.map_layers.network.DDPageRank
  • palette (DiscretePalette) – define the colours to use in conjunction with the ranking algorithm
  • marker_manager (MarkerManager) – manage the markers used to represent nodes
  • font_height (int) – font size in pixels for contour labels
  • text_attributes (dict) – a dict containing SVG name/value attributes to apply to contour labels

Example

(Link to open example in new tab):

Source Code (Link to Github):

# -*- coding: utf-8 -*-

from visigoth import Diagram
from visigoth.containers import Box, Map
from visigoth.common import Legend
from visigoth.map_layers import Network, WMS
from visigoth.map_layers.network import DDPageRank
from visigoth.utils.colour import ContinuousPalette
from visigoth.utils.marker import MarkerManager

d = Diagram()

m1 = Map(512,width_to_height=1)

nodes = [('0', -0.463, 40.588), ('1', -0.769, 40.170),
 ('2', -0.535, 40.538), ('3', -0.613, 40.026),
 ('4', -0.868, 40.759), ('5', -0.408, 40.343),
 ('6', -0.402, 40.755), ('7', -0.197, 40.580),
 ('8', -0.257, 40.688), ('9', -0.381, 40.518)]

edges = [
    ('2', '0'), ('1', '3'), ('7', '8'), ('4', '2'), ('7', '9'), ('8', '7'), ('6', '8'), ('4', '0'), ('0', '2'),
 ('8', '6'), ('3', '1'), ('0', '9'), ('5', '9'), ('1', '5'), ('9', '0'), ('5', '2'), ('1', '2'), ('8', '9'),
 ('4', '6'), ('6', '0')]

palette = ContinuousPalette()
mm = MarkerManager().setDefaultRadius(10)

nw = Network(node_data=nodes,edge_data=edges,marker_manager=mm,palette=palette,ranking_algorithm=DDPageRank())
m1.addLayer(WMS("osm").setOpacity(0.5))
m1.addLayer(nw)
d.add(Box(m1))
d.add(Legend(palette,512))
html = d.draw(format="html")

f = open("example.html", "w")
f.write(html)
f.close()