Scatter

class visigoth.charts.scatter.Scatter(data, x=0, y=1, width=768, height=768, hue=None, label=None, size=None, slice=None, hue_manager=None, marker_manager=None, font_height=24, text_attributes={}, value_formatter=None)

Create a Scatter plot

Parameters

data (list) – A relational data set (for example, list of dicts/lists/tuples describing each row)

Keyword Arguments
  • x (str or int) – Identify the column to provide the x-axis value for each point

  • y (str or int) – Identify the column to provide the y-axis value for each point

  • width (int) – the width of the plot including axes

  • height (int) – the height of the plot including axes

  • hue (str or int) – Identify the column to define the point hue (use hue_manager default hue if not specified)

  • label (str or int) – Identify the column to define the label

  • size (str or int) – Identify the column to determine the size of each marker

  • slice (str or int) – Identify the column to determine the slice to which each marker belongs

  • hue_manager (object) – a ContinuousHueManager or DiscreteHueManager instance to control chart hue

  • marker_manager (object) – a MarkerManager instance to control marker appearance

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

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

  • value_formatter (visigoth.utils.ValueFormatter) – control the way values are represented

Note

x-axis values can be int,float,datetime.datetime or datetime.timedelta y-axis values can be int,float,datetime.datetime or datetime.timedelta

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.charts import Scatter
from visigoth.utils import DiscreteHueManager, MarkerManager
from visigoth.common import DiscreteHueLegend

hue_manager = DiscreteHueManager()
marker_manager = MarkerManager()
marker_manager.setMaxRadius(10)

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

d = Diagram()

scatter = Scatter(data, x=0, y=1, label=2, hue=3, size=4,
                  hue_manager=hue_manager,marker_manager=marker_manager)
(ax,ay) = scatter.getAxes()
ax.setMinValue(0.0).setMaxValue(1.0)
ay.setMinValue(0.0).setMaxValue(1.0)
legend = DiscreteHueLegend(hue_manager,400,legend_columns=2)
legend.setDiscreteMarkerStyle("circle")

d.add(legend)
d.connect(legend,"hue",scatter,"hue")
d.connect(scatter,"hue",legend,"hue")

(xaxis,yaxis) = scatter.getAxes()
xaxis.setStroke("red",3)
yaxis.setStroke("red",3)
d.add(scatter)
html = d.draw(format="html")

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