Bar

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

Create a Bar 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 discrete values
  • y (str or int) – Identify the column to measure on the y-axis (use count if not specified)
  • colour (str or int) – Identify the column to define the bar colour (use palette default colour if not specified)
  • 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 -*-

from visigoth.diagram import Diagram
from visigoth.charts.bar import Bar
from visigoth.utils.colour import DiscretePalette
from visigoth.common.legend import Legend

palette = DiscretePalette()

data = [{"c1":"A","c2":10},{"c1":"B","c2":5},{"c1":"C","c2":6},{"c1":"D","c2":8}]

d = Diagram()

bar1 = Bar(data,x="c1",y="c2",colour="c1",width=400, height=400, palette=palette,labelfn=lambda k,v:"%d"%v)
d.add(bar1)
legend = Legend(palette,400,legend_columns=2)
d.add(legend)

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

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