Network

class visigoth.map_layers.network.Network(nodes=[], edges=[], ranking_algorithm=None, palette=None, fill='white', stroke='black', stroke_width=1, font_height=8, text_attributes={})

Create a Network plot

Keyword Arguments
  • nodes (list) – a list of node objects

  • edges (list) – a list of edge objects

  • palette (DiscretePalette) – define the colours to use in conjunction with the ranking algorithm

  • ranking_algorithm (object) – to colour nodes by rank, pass an instance of visigoth.map_layers.network.DDPageRank

  • fill (str) – the default colour to use for filling nodes

  • stroke (str) – the colour to use for contour lines

  • stroke_width (float) – the width (in pixels) to use for contour lines

  • 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

Screenshot (Link to open SVG for interactive features):

../_images/example32.png

Source Code (Link to Github):


import os.path
import sys
import argparse
import math
import random

from visigoth import Diagram
from visigoth.containers.map import Map
from visigoth.map_layers.wms  import WMS
from visigoth.utils.mapping import Mapping
from visigoth.containers.box import Box
from visigoth.common.text import Text
from visigoth.common.legend import Legend
from visigoth.map_layers.network import Network,Node,Edge,DDPageRank
from visigoth.utils.colour import ContinuousPalette


if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    d = Diagram(fill="white")

    m1 = Map(512,width_to_height=1)

    nodes = []
    edges = []
    angle = 0
    for i in range(0,10):
        angle = i * math.pi*2 / 10
        lon = 0.5+0.4*math.sin(angle)
        lat = 0.5+0.4*math.cos(angle)

        wlon = 0.5+0.3*math.sin(angle-math.pi/10)
        wlat = 0.5+0.3*math.cos(angle-math.pi/10)
        
        nodes.append(Node(lon,lat,radius=15,fill=random.choice(["red","green","blue"])))
        if len(nodes)>1:
            edges.append(Edge(nodes[-2],nodes[-1],waypoints=[(wlon,wlat)]))

    edges.append(Edge(nodes[-1],nodes[0]))
    edges.append(Edge(nodes[-1],nodes[5]))
    edges.append(Edge(nodes[0],nodes[4]))

    palette = ContinuousPalette()
    palette.addColour("green",0.0)
    palette.addColour("red",1.0)

    nw = Network(nodes=nodes,edges=edges,palette=palette,ranking_algorithm=DDPageRank())
    m1.addLayer(nw)
    d.add(Box(m1))

    d.add(Legend(palette,512))

    svg = d.draw()

    f = open(args.outpath, "wb")
    f.write(svg)
    f.close()