Kernel Density Estimate

class visigoth.map_layers.kde.KDE(data, lon=0, lat=1, hue=None, kernel=None, bandwidth=1000, nr_samples_across=20, contour_bands=10, hue_manager=None, label_fn=<function KDE.<lambda>>, font_height=8, text_attributes={})
Create a Kernel Density Estimate (KDE) plot

data (list): A relational data set (for example, list of dicts/lists/tuples describing each row)

Keyword Arguments
  • lat (str or int) – Identify the column to provide the latitude value for each point

  • lon (str or int) – Identify the column to provide the longitude value for each point

  • hue (float or int) – Attach a magnitude value to each point (if None, all points are assigned a magnitude of 1)

  • 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_bands (int) – the number of contour bands to create

  • hue_manager (ContinuousHueManager) – define the hues used in the plot


(Link to open example in new tab):

Source Code (Link to Github):

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

import random

from visigoth import Diagram
from visigoth.containers import Map, Box
from visigoth.map_layers import Scatter, KDE
from visigoth.utils import ContinuousHueManager

d = Diagram(fill="white")

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

hue_manager = ContinuousHueManager(hueMap=["yellow","red"])

m1 = Map(512,bounds)

html = d.draw(format="html")

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