Histogram

class visigoth.charts.histogram.Histogram(data, x=0, colour=None, nr_bins=15, width=512, height=512, palette=None, stroke='black', stroke_width=2, font_height=12, spacing_fraction=0.1, text_attributes={}, labelfn=<function Histogram.<lambda>>)

Create a Histogram Chart

Parameters

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

Keyword Arguments
  • x (str or int) – Identify the column to yield continuous values

  • colour (str or int) – Identify the column to define the colour (use palette default colour if not specified)

  • nr_bin (int) – The number of bins to create

  • width (int) – the width of the plot in pixels

  • height (int) – the height of the plot in pixels

  • palette (list) – a DiscretePalette object

  • stroke (str) – stroke color for bars

  • stroke_width (int) – stroke width for bars

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

  • spacing_fraction (float) – ratio of bar width to spacing

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

  • labelfn (lambda) – function to compute a label string, given a category and numeric value

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 Histogram
from visigoth.common.legend import Legend

r = random.Random()

data = []
for idx in range(0, 200):
    data.append({"value":r.gauss(1,0.2),"category":"one"})

for idx in range(0, 100):
    data.append({"value":r.gauss(2,0.4),"category":"two"})

d = Diagram()

histogram = Histogram(data,x="value",colour="category")
histogram.getPalette().setOpacity(0.5)
legend = Legend(histogram.getPalette(), width=300)

d.add(histogram)
d.add(legend)

d.connect(legend,"colour",histogram,"colour")
d.connect(histogram,"colour",legend,"colour")

html = d.draw(format="html")

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