Kernel Density Estimate

class visigoth.map_layers.kde.KDE(data, kernel=None, bandwidth=1000, nr_samples_across=20, contour_interval=0.1, palette=None, label_fn=<function KDE.<lambda>>, stroke='brown', stroke_width=0, font_height=8, text_attributes={})
Create a Kernel Density Estimate (KDE) plot

data(list) : list of (lon,lat) datapoints

Keyword Arguments
  • kernel – a kernel function mapping from distance in meters to a probability value

  • bandwidth (int) – defines the radius of the area of influence of each data point

  • nr_samples_across (int) – number of points to sample for contours across the plot

  • contour_interval (float) – height difference between contours

  • palette (ContinuousPalette) – define the colours used in the plot

  • 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


Screenshot (Link to open SVG for interactive features):


Source Code (Link to Github):

import os.path
import sys
import argparse
import random

from visigoth import Diagram
from import Map
from import Box
from visigoth.map_layers.kde import KDE
from visigoth.map_layers.scatter import Scatter
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")

    rng = random.Random()
    bounds = ((0,0),(1,1))
    data = [(rng.random(),rng.random()) for x in range(0,100)]

    palette = ContinuousPalette()

    m1 = Map(512,bounds)

    svg = d.draw()

    f = open(args.outpath, "wb")