Line

class visigoth.charts.line.Line(lines, width, height, palette, draw_grid=True, smoothing=0.3, line_width=4, point_radius=4, x_axis_label=None, y_axis_label=None, stroke='black', stroke_width=2, font_height=24, text_attributes={}, x_axis_max=None, x_axis_min=None, y_axis_max=None, y_axis_min=None)

Create an Line plot

Parameters
  • lines (list) – line data in the form [(category,label,[(x,y)])]

  • width (int) – the width of the plotting area in pixels (not including x-axis)

  • height (int) – the height of the plotting area in pixels (not including y-axis)

  • palette (list) – a list of (category, colour) pairs

Keyword Arguments
  • draw_grid (boolean) – whether to draw gridlines

  • smoothing (float) – smoothing factor to apply to lines, 0.0=no smoothing

  • line_width (int) – width of the lines

  • point_radius (int) – radius of points

  • x_axis_label (str) – label for the x axis

  • y_axis_label (str) – label for the y axis

  • stroke (str) – stroke color for circumference of points

  • stroke_width (int) – stroke width for circumference of points

  • font_height (int) – the height of the font for text labels

  • text_attributes (dict) – SVG attribute name value pairs to apply to labels

  • x_axis_max (int|float) – set the maximum value on the x axis

  • x_axis_min (int|float) – set the minimum value on the x axis

  • y_axis_max (int|float) – set the maximum value on the y axis

  • y_axis_min (int|float) – set the minimum value on the y axis

Example

Screenshot (Link to open SVG for interactive features):

../_images/example2.png

Source Code (Link to Github):


import os.path
import sys
import argparse
import random
import datetime

from visigoth.diagram import Diagram
from visigoth.charts.line import Line
from visigoth.containers.box import Box
from visigoth.utils.colour import DiscretePalette
from visigoth.common.legend import Legend
from visigoth.common.button import Button
from visigoth.common.text import Text
from visigoth.common.space import Space

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    palette = DiscretePalette()
    palette.addCategory("A","#E7FFAC")
    palette.addCategory("B","#FFC9DE")
    palette.addCategory("C","#B28DFF")
    palette.addCategory("D","#ACE7FF")

    r = random.Random()
    data = []
    y = -0.05
    for cat in ["A","B","C","D"]:
        linedata = []
        for idx in range(36):
            linedata.append((datetime.datetime(2018,1,1,0,idx,0),y+r.random()/10))
        y += 0.1
        data.append((cat,cat,linedata))

    d = Diagram(fill="white")

    al = Line(data, 600, 600, palette, x_axis_label="X", y_axis_label="Y")
    ax = al.getXAxis()
    # ax.setTickPositions([datetime.datetime(2018,idx+1,1,0,0,0) for idx in range(1,12,3)])

    d.add(Box(al))
  
    legend = Legend(palette,400,legend_columns=2)
    d.add(legend)
    d.connect(legend,al,"brushing")
    d.connect(al,legend,"brushing")

    svg = d.draw()

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