ScatterPlot

class visigoth.charts.scatterplot.ScatterPlot(scatter, width, height, palette, x_axis_label=None, y_axis_label=None, draw_grid=True, 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 a Scatter plot

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

  • 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
  • x_axis_label (str) – label for the x axis

  • y_axis_label (str) – label for the y axis

  • draw_grid (boolean) – whether to draw grid lines

  • 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/example4.png

Source Code (Link to Github):


import os.path
import sys
import argparse
import random

from visigoth.diagram import Diagram
from visigoth.charts.scatterplot import ScatterPlot
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 = []
    for idx in range(0,100):
        data.append((r.random(),r.random(),"p"+str(idx),r.choice(["A","B","C","D"]),r.choice([3,5,9])))

    data.append((0.0,0.0,"origin",r.choice(["A","B","C","D"]),4))

    d = Diagram(fill="white")

    scatter = ScatterPlot(data, 500, 500, palette, x_axis_label="X AXIS", y_axis_label="Y AXIS")
    d.add(Space(20,20))
    legend = Legend(palette,400,legend_columns=2)
    d.add(legend)
    d.connect(legend,scatter,"brushing")
    d.connect(scatter,legend,"brushing")


    xaxis = scatter.getXAxis()
    xaxis.setStroke("red",3)
    yaxis = scatter.getYAxis()
    yaxis.setStroke("blue",3)
    d.add(scatter)
    svg = d.draw()

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