Iris

Example

(Link to open example in new tab):

Source Code (Link to Github):

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

import random
import csv

from visigoth.diagram import Diagram
from visigoth.common import Text, DiscreteHueLegend
from visigoth.containers import Grid, Sequence, Box
from visigoth.charts import Scatter, Histogram
from visigoth.utils import DiscreteHueManager, MarkerManager, ChartFormatter

rng = random.Random()
d = Diagram(fill="white")

data = []
reader = csv.reader(open("iris.csv"))
keys = {}
data = []
for line in reader:
    if not keys:
        for idx in range(0,len(line)):
            keys[line[idx]] = idx
    else:
        data.append({k:line[keys[k]] for k in keys})

p = DiscreteHueManager()
g = Grid()

fields = ["sepal_length","sepal_width","petal_length","petal_width"]

mm = MarkerManager(default_radius=2)

def createPlot(x_field,y_field,data,hue_manager,chart_formatter):
    sdata = [(float(row[x_field]),float(row[y_field]),row["species"]) for row in data]
    if x_field != y_field:
        sp = Scatter(sdata, hue=2, hue_manager=hue_manager)
        sp.setDrawGrid(False)
        sp.setChartFormatter(chart_formatter)
        (ax,ay) = sp.getAxes()
        ax.setLabel(x_field)
        ay.setLabel(y_field)
        return sp
    else:
        s = Sequence(orientation="vertical",spacing=10)
        min_value = min([float(row[x_field]) for row in data])
        max_value = max([float(row[x_field]) for row in data])

        for species in ["versicolor","virginica","setosa"]:
            sdata = [[float(row[x_field]),row["species"]] for row in data if row["species"] == species]
            hs = Histogram(sdata,x=0,hue=1,hue_manager=hue_manager,width=300,height=65)
            hs.setDrawGrid(False)
            (ax, ay) = hs.getAxes()
            ax.setMinValue(min_value).setMaxValue(max_value)
            ax.setLabel("")
            ay.setLabel("")
            s.add(hs)
        s.add(Text(x_field))
        return s

l = DiscreteHueLegend(p,width=800,legend_columns=3)
cf = ChartFormatter(width=300,height=300,font_height=10)
for r in range(len(fields)):
    for c in range(len(fields)):
        x_field = fields[r]
        y_field = fields[c]
        e = createPlot(x_field,y_field,data,p,cf)
        g.add(r,c,e)
d.add(g)
d.add(l)
html = d.draw(format="html")

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