Hexbin

class visigoth.map_layers.hexbin.Hexbin(data, nr_bins_across=10, palette=None, stroke='brown', stroke_width=1)
Create a Hexagonally binned plot of point density

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

Keyword Arguments
  • nr_bins_across – number of bins to arrange across the plot

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

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

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

Example

Screenshot (Link to open SVG for interactive features):

../_images/example30.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.utils.mapping import Mapping
from visigoth.containers.box import Box
from visigoth.common.text import Text
from visigoth.map_layers.hexbin import Hexbin
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()
    palette.addColour("#0000FF",0.0).addColour("#FF0000",1.0)

    m1 = Map(512,bounds)
    m1.addLayer(Hexbin(data,palette=palette,stroke=None))
    m1.addLayer(Scatter(data))
    d.add(Box(m1,padding=0))

    svg = d.draw()

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