Voronoi

class visigoth.map_layers.voronoi.Voronoi(data, stroke='black', stroke_width=2, radius=5)

Create a Voronoi plot

Parameters

data (list) – (x,y,col,label) tuples for each point

Keyword Arguments
  • stroke (str) – stroke color for plotting boundaries

  • stroke_width (int) – stroke width for plotting boundaries

  • radius (int) – radius for plotting region centers (set to 0 to omit)

Example

Screenshot (Link to open SVG for interactive features):

../_images/example35.png

Source Code (Link to Github):


import os.path
import sys
import argparse
import random

from visigoth import Diagram
from visigoth.containers.map import Map
from visigoth.map_layers.voronoi  import Voronoi

from visigoth.containers.box import Box
from visigoth.common.text import Text
from visigoth.common.space import Space

from visigoth.utils.colour import Colour
from visigoth.utils.mapping import Projections

if __name__ == "__main__":

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

    rng = random.Random()
    data = [(rng.random(),rng.random(),Colour.randomColour(),"area(%d)"%(i)) for i in range(200)]

    d = Diagram(fill="white")
    m = Map(512,boundaries=((0.0,0.0),(1.0,1.0)),projection=Projections.ESPG_4326)
    v = Voronoi(data,radius=5)
    m.addLayer(v)
    d.add(Box(m))

    svg = d.draw()

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