Chloropleth

class visigoth.map_layers.chloropleth.Chloropleth(path, valueNameOrFn, labelNameOrFn, palette, default_fill_colour='white', stroke='black', stroke_width=2)

Create a Choloropleth plot from a geojson file

Parameters:
  • path – 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
  • labelNameOrFn (str|function) – the name of the property (or function of the properties dict) to provide the label
  • palette (list) – a list of (value, colour) pairs or a list of [(min-value, min-colour),(max-value,max-colour)]
Keyword Arguments:
 
  • default_fill_colour (str) – default colour for areas where a value cannot be obtained
  • stroke (str) – stroke color for circumference of circles
  • stroke_width (int) – stroke width for circumference of circles

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.chloropleth import Chloropleth
from visigoth.common import Text, Space, Legend
from visigoth.utils.colour import ContinuousPalette
import os.path

palette = ContinuousPalette()
palette.addColour("green",0.0).addColour("blue",10.0)

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

path = os.path.join(os.path.split(__file__)[0],"aus_state.geojson")
d.add(Text("randomness",font_height=50,text_attributes={"stroke":"purple"}))
d.add(Space(20,20))
c = Chloropleth(path,lambda props:rng.random()*10,"STATE_NAME",palette)
m = Map(512,zoom_to=4)
m.addLayer(c)
d.add(Box(m))
d.add(Space(20,20))
d.add(Legend(palette,width=500,legend_columns=3))
html = d.draw(format="html")

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