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

Screenshot (Link to open SVG for interactive features):

../_images/example25.png

Source Code (Link to Github):


import os.path
import sys
import argparse
import math

from visigoth import Diagram
from visigoth.containers.map  import Map
from visigoth.map_layers.contour  import Contour
from visigoth.utils.colour import ContinuousPalette
from visigoth.containers.box import Box
from visigoth.containers.sequence import Sequence
from visigoth.utils.mapping import Projections



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")

    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))

    svg = d.draw()

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