Choropleth

class visigoth.map_layers.choropleth.Choropleth(path, valueNameOrFn, labelNameOrFn=None, hue_manager=None, stroke='black', stroke_width=2)

Create a Choropleth plot from a geojson file

Parameters
  • path (str) – file path to a geojson file

  • valueNameOrFn (str|function) – the name of the property (or function of the properties dict) to provide the value to visualize

Keyword Arguments
  • labelNameOrFn (str|function) – the name of the property (or function of the properties dict) to provide the label

  • hue_manager (DiscreteHueManager|ContinuousHueManager) – a DiscreteHueManager|ContinuousHueManager object for mapping values to hues

  • stroke (str) – stroke color

  • stroke_width (int) – stroke width

Notes:

Example

(Link to open example in new tab):

Source Code (Link to Github):

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

import random

from visigoth.diagram import Diagram
from visigoth.containers import Map, Box
from visigoth.map_layers.choropleth import Choropleth
from visigoth.common import ContinuousHueLegend
from visigoth.utils import ContinuousHueManager
import os.path

hue_manager = ContinuousHueManager()

rng = random.Random()
d = Diagram(fill="white")

path = os.path.join(os.path.split(__file__)[0],"aus_state.geojson")

c = Choropleth(path, lambda props:int(props["STATE_CODE"]), None, hue_manager)
m = Map(512,zoom_to=4)
m.add(c)
d.add(Box(m))
d.add(ContinuousHueLegend(hue_manager,length=500,font_height=10))
html = d.draw(format="html")

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