chaco.overlays.legend module

Defines the Legend, AbstractCompositeIconRenderer, and CompositeIconRenderer classes.

class chaco.overlays.legend.AbstractCompositeIconRenderer

Bases: traits.has_traits.HasTraits

Abstract class for an icon renderer.

render_icon(plots, gc, x, y, width, height)

Renders an icon representing the given list of plots onto the graphics context, using the given dimensions and at the specified position.

class chaco.overlays.legend.CompositeIconRenderer

Bases: chaco.overlays.legend.AbstractCompositeIconRenderer

Renderer for composite icons.

render_icon(plots, *render_args)

Renders an icon for a list of plots.

class chaco.overlays.legend.Legend(component=None, *args, **kw)

Bases: chaco.abstract_overlay.AbstractOverlay

A legend for a plot.

align = Enum("ur", "ul", "ll", "lr")

The position of the legend with respect to its overlaid component. (This attribute applies only if the legend is used as an overlay.)

  • ur = Upper Right

  • ul = Upper Left

  • ll = Lower Left

  • lr = Lower Right

bgcolor = white_color_trait

The background color of the legend (overrides AbstractOverlay).

border_padding = Int(10)

The amount of space between the content of the legend and the border.

border_visible = True

The border is visible (overrides Enable Component).

clip_to_component = Bool(False)

Should the legend clip to the bounds it needs, or to its parent?

color = black_color_trait

The color of the text labels

composite_icon_renderer = Instance(AbstractCompositeIconRenderer)

The renderer that draws the icons for the legend.

draw_layer = "overlay"

The legend is drawn on the overlay layer of its parent (overrides PlotComponent).

error_icon = Enum("skip", "blank", "questionmark")

Action that the legend takes when it encounters a plot whose icon it cannot render:

  • ‘skip’: skip it altogether and don’t render its name

  • ‘blank’: render the name but leave the icon blank (color=self.bgcolor)

  • ‘questionmark’: render a “question mark” icon

font = KivaFont("modern 12")

The font to use for the legend text.

get_label_at(x, y)

Returns the label object at (x,y)

get_preferred_size()

Computes the size and position of the legend based on the maximum size of the labels, the alignment, and position of the component to overlay.

hide_invisible_plots = Bool(True)

Whether or not to hide plots that are not visible. (This is checked during layout.) This option will filter out the items in labels above, so if you absolutely, positively want to set the items that will always display in the legend, regardless of anything else, then you should turn this option off. Otherwise, it usually makes sense that a plot renderer that is not visible will also not be in the legend.

icon_bounds = List([24, 24])

The size of the icon or marker area drawn next to the label.

icon_spacing = Int(5)

Amount of spacing between each label and its icon.

invisible_plot_alpha = Float(0.33)

If hide_invisible_plots is False, we can still choose to render the names of invisible plots with an alpha.

is_in(x, y)

overloads from parent class because legend alignment and padding does not cooperatate with the basic implementation

This may just be caused byt a questionable implementation of the legend tool, but it works by adjusting the padding. The Component class implementation of is_in uses the outer positions which includes the padding

labels = List

The list of labels to show and the order to show them in. If this list is blank, then the keys of self.plots is used and displayed in alphabetical order. Otherwise, only the items in the labels list are drawn in the legend. Labels are ordered from top to bottom.

line_spacing = Int(3)

The amount of space between legend items.

overlay(component, gc, view_bounds=None, mode='normal')

Draws this component overlaid on another component.

Implements AbstractOverlay.

plots = Dict

Map of labels (strings) to plot instances or lists of plot instances. The Legend determines the appropriate rendering of each plot’s marker/line.

resizable = "hv"

The legend is not resizable (overrides PlotComponent).

title = Str()

An optional title string to show on the legend.

title_at_top = Bool(True)

If True, title is at top, if False then at bottom.

unified_draw = True

The legend draws itself as in one pass when its parent is drawing the draw_layer (overrides PlotComponent).