Contour

class visigoth.map_layers.contour.Contour(data=[], contour_interval=10, palette=None, label_fn=<function Contour.<lambda>>, stroke='brown', stroke_width=1, font_height=8, text_attributes={})

Create a Contour plot

Keyword Arguments:
 
  • data (list) – list of rows, where each row is an equal size list of column values values
  • contour_interval (float) – gap between contours
  • label_fn (function) – function to compute a str contour label from a numeric threshold
  • 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

Example

(Link to open example in new tab):

Source Code (Link to Github):

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

import argparse
import math

from visigoth import Diagram
from visigoth.containers import Map, Box
from visigoth.map_layers import Contour
from visigoth.utils.mapping import Projections

d = Diagram()

peaks = [(0.3,0.3,100),(0.1,0.9,150),(0.6,0.7,120)]

def computeHeight(x,y):
    h = 0
    for (cx,cy,height) in peaks:
        d = math.sqrt((x-cx)**2+(y-cy)**2)
        h += height*math.exp(-3*d)
    return h

data = []
resolution=100
for y in range(resolution):
    data.append([computeHeight(x/resolution,y/resolution) for x in range(resolution)])

m = Map(512,boundaries=((20.0,20.0),(21.0,21.0)),projection=Projections.ESPG_3857)
c = Contour(data,10,stroke_width=0.5)
m.addLayer(c)
d.add(Box(m))

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

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