altair.LegendConfig

class altair.LegendConfig(clipHeight=Undefined, columnPadding=Undefined, columns=Undefined, cornerRadius=Undefined, direction=Undefined, disable=Undefined, fillColor=Undefined, gradientDirection=Undefined, gradientHorizontalMaxLength=Undefined, gradientHorizontalMinLength=Undefined, gradientLabelLimit=Undefined, gradientLabelOffset=Undefined, gradientLength=Undefined, gradientOpacity=Undefined, gradientStrokeColor=Undefined, gradientStrokeWidth=Undefined, gradientThickness=Undefined, gradientVerticalMaxLength=Undefined, gradientVerticalMinLength=Undefined, gridAlign=Undefined, labelAlign=Undefined, labelBaseline=Undefined, labelColor=Undefined, labelFont=Undefined, labelFontSize=Undefined, labelFontStyle=Undefined, labelFontWeight=Undefined, labelLimit=Undefined, labelOffset=Undefined, labelOpacity=Undefined, labelOverlap=Undefined, labelPadding=Undefined, labelSeparation=Undefined, layout=Undefined, legendX=Undefined, legendY=Undefined, offset=Undefined, orient=Undefined, padding=Undefined, rowPadding=Undefined, strokeColor=Undefined, strokeDash=Undefined, strokeWidth=Undefined, symbolBaseFillColor=Undefined, symbolBaseStrokeColor=Undefined, symbolDash=Undefined, symbolDashOffset=Undefined, symbolDirection=Undefined, symbolFillColor=Undefined, symbolLimit=Undefined, symbolOffset=Undefined, symbolOpacity=Undefined, symbolSize=Undefined, symbolStrokeColor=Undefined, symbolStrokeWidth=Undefined, symbolType=Undefined, tickCount=Undefined, title=Undefined, titleAlign=Undefined, titleAnchor=Undefined, titleBaseline=Undefined, titleColor=Undefined, titleFont=Undefined, titleFontSize=Undefined, titleFontStyle=Undefined, titleFontWeight=Undefined, titleLimit=Undefined, titleLineHeight=Undefined, titleOpacity=Undefined, titleOrient=Undefined, titlePadding=Undefined, unselectedOpacity=Undefined, **kwds)

LegendConfig schema wrapper

Mapping(required=[])

Attributes
clipHeightfloat

The height in pixels to clip symbol legend entries and limit their size.

columnPaddingfloat

The horizontal padding in pixels between symbol legend entries.

Default value: 10.

columnsfloat

The number of columns in which to arrange symbol legend entries. A value of 0 or lower indicates a single row with one column per entry.

cornerRadiusfloat

Corner radius for the full legend.

directionOrientation

The direction of the legend, one of "vertical" or "horizontal".

Default value:

  • For top-/bottom- orient ed legends, "horizontal"

  • For left-/right- orient ed legends, "vertical"

  • For top/bottom-left/right- orient ed legends, "horizontal" for gradient legends and "vertical" for symbol legends.

disableboolean

Disable legend by default

fillColoranyOf(None, Color)

Background fill color for the full legend.

gradientDirectionOrientation

The default direction ( "horizontal" or "vertical" ) for gradient legends.

Default value: "vertical".

gradientHorizontalMaxLengthfloat

Max legend length for a horizontal gradient when config.legend.gradientLength is undefined.

Default value: 200

gradientHorizontalMinLengthfloat

Min legend length for a horizontal gradient when config.legend.gradientLength is undefined.

Default value: 100

gradientLabelLimitfloat

The maximum allowed length in pixels of color ramp gradient labels.

gradientLabelOffsetfloat

Vertical offset in pixels for color ramp gradient labels.

Default value: 2.

gradientLengthfloat

The length in pixels of the primary axis of a color gradient. This value corresponds to the height of a vertical gradient or the width of a horizontal gradient.

Default value: 200.

gradientOpacityfloat

Opacity of the color gradient.

gradientStrokeColoranyOf(None, Color)

The color of the gradient stroke, can be in hex color code or regular color name.

Default value: "lightGray".

gradientStrokeWidthfloat

The width of the gradient stroke, in pixels.

Default value: 0.

gradientThicknessfloat

The thickness in pixels of the color gradient. This value corresponds to the width of a vertical gradient or the height of a horizontal gradient.

Default value: 16.

gradientVerticalMaxLengthfloat

Max legend length for a vertical gradient when config.legend.gradientLength is undefined.

Default value: 200

gradientVerticalMinLengthfloat

Min legend length for a vertical gradient when config.legend.gradientLength is undefined.

Default value: 100

gridAlignLayoutAlign

The alignment to apply to symbol legends rows and columns. The supported string values are "all", "each" (the default), and none. For more information, see the grid layout documentation.

Default value: "each".

labelAlignAlign

The alignment of the legend label, can be left, center, or right.

labelBaselineTextBaseline

The position of the baseline of legend label, can be "top", "middle", "bottom", or "alphabetic".

Default value: "middle".

labelColoranyOf(None, Color)

The color of the legend label, can be in hex color code or regular color name.

labelFontstring

The font of the legend label.

labelFontSizefloat

The font size of legend label.

Default value: 10.

labelFontStyleFontStyle

The font style of legend label.

labelFontWeightFontWeight

The font weight of legend label.

labelLimitfloat

Maximum allowed pixel width of legend tick labels.

Default value: 160.

labelOffsetfloat

The offset of the legend label.

labelOpacityfloat

Opacity of labels.

labelOverlapLabelOverlap

The strategy to use for resolving overlap of labels in gradient legends. If false, no overlap reduction is attempted. If set to true or "parity", a strategy of removing every other label is used. If set to "greedy", a linear scan of the labels is performed, removing any label that overlaps with the last visible label (this often works better for log-scaled axes).

Default value: "greedy" for log scales otherwise true`.

labelPaddingfloat

Padding in pixels between the legend and legend labels.

labelSeparationfloat

The minimum separation that must be between label bounding boxes for them to be considered non-overlapping (default 0 ). This property is ignored if labelOverlap resolution is not enabled.

layoutnot Any

Legend orient group layout parameters.

legendXfloat

Custom x-position for legend with orient “none”.

legendYfloat

Custom y-position for legend with orient “none”.

offsetfloat

The offset in pixels by which to displace the legend from the data rectangle and axes.

Default value: 18.

orientLegendOrient

The orientation of the legend, which determines how the legend is positioned within the scene. One of "left", "right", "top", "bottom", "top-left", "top-right", "bottom-left", "bottom-right", "none".

Default value: "right"

paddingfloat

The padding between the border and content of the legend group.

Default value: 0.

rowPaddingfloat

The vertical padding in pixels between symbol legend entries.

Default value: 2.

strokeColoranyOf(None, Color)

Border stroke color for the full legend.

strokeDashList(float)

Border stroke dash pattern for the full legend.

strokeWidthfloat

Border stroke width for the full legend.

symbolBaseFillColoranyOf(None, Color)

Default fill color for legend symbols. Only applied if there is no "fill" scale color encoding for the legend.

Default value: "transparent".

symbolBaseStrokeColoranyOf(None, Color)

Default stroke color for legend symbols. Only applied if there is no "fill" scale color encoding for the legend.

Default value: "gray".

symbolDashList(float)

An array of alternating [stroke, space] lengths for dashed symbol strokes.

symbolDashOffsetfloat

The pixel offset at which to start drawing with the symbol stroke dash array.

symbolDirectionOrientation

The default direction ( "horizontal" or "vertical" ) for symbol legends.

Default value: "vertical".

symbolFillColoranyOf(None, Color)

The color of the legend symbol,

symbolLimitfloat

The maximum number of allowed entries for a symbol legend. Additional entries will be dropped.

symbolOffsetfloat

Horizontal pixel offset for legend symbols.

Default value: 0.

symbolOpacityfloat

Opacity of the legend symbols.

symbolSizefloat

The size of the legend symbol, in pixels.

Default value: 100.

symbolStrokeColoranyOf(None, Color)

Stroke color for legend symbols.

symbolStrokeWidthfloat

The width of the symbol’s stroke.

Default value: 1.5.

symbolTypeSymbolShape

The symbol shape. One of the plotting shapes circle (default), square, cross, diamond, triangle-up, triangle-down, triangle-right, or triangle-left, the line symbol stroke, or one of the centered directional shapes arrow, wedge, or triangle. Alternatively, a custom SVG path string can be provided. For correct sizing, custom shape paths should be defined within a square bounding box with coordinates ranging from -1 to 1 along both the x and y dimensions.

Default value: "circle".

tickCountTickCount

The desired number of tick values for quantitative legends.

titleNone

Set to null to disable title for the axis, legend, or header.

titleAlignAlign

Horizontal text alignment for legend titles.

Default value: "left".

titleAnchorTitleAnchor

Text anchor position for placing legend titles.

titleBaselineTextBaseline

Vertical text baseline for legend titles.

Default value: "top".

titleColoranyOf(None, Color)

The color of the legend title, can be in hex color code or regular color name.

titleFontstring

The font of the legend title.

titleFontSizefloat

The font size of the legend title.

titleFontStyleFontStyle

The font style of the legend title.

titleFontWeightFontWeight

The font weight of the legend title. This can be either a string (e.g "bold", "normal" ) or a number ( 100, 200, 300, …, 900 where "normal" = 400 and "bold" = 700 ).

titleLimitfloat

Maximum allowed pixel width of legend titles.

Default value: 180.

titleLineHeightfloat

Line height in pixels for multi-line title text.

titleOpacityfloat

Opacity of the legend title.

titleOrientOrient

Orientation of the legend title.

titlePaddingfloat

The padding, in pixels, between title and legend.

Default value: 5.

unselectedOpacityfloat

The opacity of unselected legend entries.

Default value: 0.35.

__init__(self, clipHeight=Undefined, columnPadding=Undefined, columns=Undefined, cornerRadius=Undefined, direction=Undefined, disable=Undefined, fillColor=Undefined, gradientDirection=Undefined, gradientHorizontalMaxLength=Undefined, gradientHorizontalMinLength=Undefined, gradientLabelLimit=Undefined, gradientLabelOffset=Undefined, gradientLength=Undefined, gradientOpacity=Undefined, gradientStrokeColor=Undefined, gradientStrokeWidth=Undefined, gradientThickness=Undefined, gradientVerticalMaxLength=Undefined, gradientVerticalMinLength=Undefined, gridAlign=Undefined, labelAlign=Undefined, labelBaseline=Undefined, labelColor=Undefined, labelFont=Undefined, labelFontSize=Undefined, labelFontStyle=Undefined, labelFontWeight=Undefined, labelLimit=Undefined, labelOffset=Undefined, labelOpacity=Undefined, labelOverlap=Undefined, labelPadding=Undefined, labelSeparation=Undefined, layout=Undefined, legendX=Undefined, legendY=Undefined, offset=Undefined, orient=Undefined, padding=Undefined, rowPadding=Undefined, strokeColor=Undefined, strokeDash=Undefined, strokeWidth=Undefined, symbolBaseFillColor=Undefined, symbolBaseStrokeColor=Undefined, symbolDash=Undefined, symbolDashOffset=Undefined, symbolDirection=Undefined, symbolFillColor=Undefined, symbolLimit=Undefined, symbolOffset=Undefined, symbolOpacity=Undefined, symbolSize=Undefined, symbolStrokeColor=Undefined, symbolStrokeWidth=Undefined, symbolType=Undefined, tickCount=Undefined, title=Undefined, titleAlign=Undefined, titleAnchor=Undefined, titleBaseline=Undefined, titleColor=Undefined, titleFont=Undefined, titleFontSize=Undefined, titleFontStyle=Undefined, titleFontWeight=Undefined, titleLimit=Undefined, titleLineHeight=Undefined, titleOpacity=Undefined, titleOrient=Undefined, titlePadding=Undefined, unselectedOpacity=Undefined, **kwds)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self[, clipHeight, columnPadding, …])

Initialize self.

copy(self[, deep, ignore])

Return a copy of the object

from_dict(dct[, validate, _wrapper_classes])

Construct class from a dictionary representation

from_json(json_string[, validate])

Instantiate the object from a valid JSON string

resolve_references([schema])

Resolve references in the context of this object’s schema or root schema.

to_dict(self[, validate, ignore, context])

Return a dictionary representation of the object

to_json(self[, validate, ignore, context, …])

Emit the JSON representation for this object as a string.

validate(instance[, schema])

Validate the instance against the class schema in the context of the rootschema.

validate_property(name, value[, schema])

Validate a property against property schema in the context of the rootschema

copy(self, deep=True, ignore=())

Return a copy of the object

Parameters
deepboolean or list, optional

If True (default) then return a deep copy of all dict, list, and SchemaBase objects within the object structure. If False, then only copy the top object. If a list or iterable, then only copy the listed attributes.

ignorelist, optional

A list of keys for which the contents should not be copied, but only stored by reference.

classmethod from_dict(dct, validate=True, _wrapper_classes=None)

Construct class from a dictionary representation

Parameters
dctdictionary

The dict from which to construct the class

validateboolean

If True (default), then validate the input against the schema.

_wrapper_classeslist (optional)

The set of SchemaBase classes to use when constructing wrappers of the dict inputs. If not specified, the result of cls._default_wrapper_classes will be used.

Returns
objSchema object

The wrapped schema

Raises
jsonschema.ValidationError :

if validate=True and dct does not conform to the schema

classmethod from_json(json_string, validate=True, **kwargs)

Instantiate the object from a valid JSON string

Parameters
json_stringstring

The string containing a valid JSON chart specification.

validateboolean

If True (default), then validate the input against the schema.

**kwargs :

Additional keyword arguments are passed to json.loads

Returns
chartChart object

The altair Chart object built from the specification.

classmethod resolve_references(schema=None)

Resolve references in the context of this object’s schema or root schema.

to_dict(self, validate=True, ignore=None, context=None)

Return a dictionary representation of the object

Parameters
validateboolean or string

If True (default), then validate the output dictionary against the schema. If “deep” then recursively validate all objects in the spec. This takes much more time, but it results in friendlier tracebacks for large objects.

ignorelist

A list of keys to ignore. This will not passed to child to_dict function calls.

contextdict (optional)

A context dictionary that will be passed to all child to_dict function calls

Returns
dctdictionary

The dictionary representation of this object

Raises
jsonschema.ValidationError :

if validate=True and the dict does not conform to the schema

to_json(self, validate=True, ignore=[], context={}, indent=2, sort_keys=True, **kwargs)

Emit the JSON representation for this object as a string.

Parameters
validateboolean or string

If True (default), then validate the output dictionary against the schema. If “deep” then recursively validate all objects in the spec. This takes much more time, but it results in friendlier tracebacks for large objects.

ignorelist

A list of keys to ignore. This will not passed to child to_dict function calls.

contextdict (optional)

A context dictionary that will be passed to all child to_dict function calls

indentinteger, default 2

the number of spaces of indentation to use

sort_keysboolean, default True

if True, sort keys in the output

**kwargs

Additional keyword arguments are passed to json.dumps()

Returns
specstring

The JSON specification of the chart object.

classmethod validate(instance, schema=None)

Validate the instance against the class schema in the context of the rootschema.

classmethod validate_property(name, value, schema=None)

Validate a property against property schema in the context of the rootschema