Legend

class visigoth.common.legend.Legend(manager, width=512, label=None, value_formatter=None, stroke='black', stroke_width=2, font_height=24, text_attributes={})

Create a general legend graphic associated with a manager

Parameters

manager (visigoth.utils.ContinuousHueManager|DiscreteHueManager) – a hue_manager object

Keyword Arguments
  • width (int) – width or length of the legend area (depending upon the type of legend)

  • label (str) – a descriptive label to display

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

  • stroke (str) – the stroke hue 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

Note

for more options, consider directly constructing a DiscreteHueLegend or ContinuousHueLegend instance

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, DiscreteHueLegend, ContinuousHueLegend
from visigoth.utils import ContinuousHueManager, DiscreteHueManager

discrete_hue_manager = DiscreteHueManager()
discrete_hue_manager.addHue("A", "green").addHue("B", "blue").addHue("C", "red").addHue("D", "orange").addHue("E","purple")

continuous_hue_manager = ContinuousHueManager(withIntervals=False)
continuous_hue_manager.allocateHue(0)
continuous_hue_manager.allocateHue(10)

d = Diagram(fill="white")
d.add(DiscreteHueLegend(discrete_hue_manager,width=700,legend_columns=3))
d.add(ContinuousHueLegend(continuous_hue_manager,length=700,orientation="horizontal"))

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

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