Legend

class visigoth.common.legend.Legend(palette, width=512, label=None, orientation='horizontal', legend_columns=0, stroke='black', stroke_width=2, font_height=24, text_attributes={}, decimal_places=3)

Create a legend graphic describing the colours used in a palette

Parameters:

palette (visigoth.utils.colour.Palette) – a palette object

Keyword Arguments:
 
  • width (int) – width of the legend area
  • label (str) – a descriptive label to display
  • orientation (str) – “horizontal”|”vertical” whether to display legend horizontally or vertically (continuous palette)
  • legend_columns (int) – the number of columns to split the legend into
  • stroke (str) – the stroke colour for the line around the toggle control
  • stroke_width (int) – the stroke width for the line around the toggle control
  • font_height (int) – the font size for the legend (optional, defaults to 24)
  • text_attributes (dict) – a dict containing SVG name/value pairs
  • decimal_places (int) – the number of decimal places to display

Example

(Link to open example in new tab):

Source Code (Link to Github):

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

from visigoth import Diagram
from visigoth.common import Legend
from visigoth.utils.colour import ContinuousPalette, DiscretePalette

discrete_palette = DiscretePalette()
discrete_palette.addCategory("A", "green").addCategory("B", "blue").addCategory("C", "red").addCategory("D", "orange").addCategory("E","purple")

continuous_palette = ContinuousPalette(withIntervals=False)

d = Diagram(fill="white")
d.add(Legend(discrete_palette,width=700, legend_columns=3))
d.add(Legend(continuous_palette,700))

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

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