SwatchLegend

SwatchLegend[{col1,},{lbl1,}]

generates a legend that associates swatches of colors coli with labels lbli.

SwatchLegend[{col1,},Automatic]

generates a legend with placeholder labels for the colors coli.

SwatchLegend[{lbl1,}]

represents a legend with inherited colors within visualization functions.

Details and Options

  • SwatchLegend uses a shape with color coli to identify label lbli with elements in the visualization or other legended item.
  • Legended[expr,SwatchLegend[]] can be used to apply a legend to an arbitrary expression expr.
  • The following options can be given:
  • LabelStyle Automaticstyle to use for labels
    LegendFunction Identitywrapper for the overall legend
    LegendLabel Noneoverall label for legend
    LegendLayout Automaticlegend layout to use
    LegendMarginsAutomaticspace between legend content and boundaries
    LegendMarkers Automaticmarkers to use to indicate each element
    LegendMarkerSize Automaticsize of the shape
  • SwatchLegend is displayed in StandardForm as a table. In InputForm it is displayed as an explicit list of colors and labels.
  • In SwatchLegend, LegendLayout can have the following forms:
  • Automaticautomatically determine layout
    "Row"display legend in a horizontal row
    "Column"display legend in a vertical column
    "ReversedRow"display reversed legend in a horizontal row
    "ReversedColumn"display reversed legend in a vertical column
    fapply f to construct the legend
  • The layout specification f is applied to the table of values {{col1,lbl1},} to generate the legend.
  • With LegendLayout->Automatic, the layout used will depend on the location relative to the object being legended.

Examples

open allclose all

Basic Examples  (1)

A list of styles and labels:

Use default labels:

Used in plots:

Scope  (13)

Data  (8)

Use style primitives:

Use Directive to combine directives in a style:

SwatchLegend uses the shorter list of styles and labels:

Use index colors:

Use gradient color schemes:

Placeholder is used by default:

SwatchLegend remains unevaluated in other cases:

SwatchLegend normally displays in tabular form:

InputForm shows a textual form:

Presentation  (5)

SwatchLegend line wraps automatically:

SwatchLegend automatically picks up styles when used in plots:

Use automatic formulas as legends:

Change the default look of SwatchLegend and the position:

Use Legended to legend Graphics with SwatchLegend:

Options  (23)

LabelStyle  (3)

All labels have the same default style:

Specify styles to labels:

LabelStyle applies to LegendLabel:

LegendFunction  (4)

Use a stylized frame:

Use Panel:

Use a customized frame:

Create a legend with a drop shadow:

LegendLabel  (5)

Add an overall label to the legend:

The label from LegendLabel is included in the argument to LegendFunction:

Construct a LegendFunction using Labeled that has a label outside:

Use LabelStyle to style the legend label:

Use Placed to change the legend label position:

Use the third argument in Placed to rotate the legend label:

LegendLayout  (4)

Arrange the legend in a row:

Arrange the legend in a column:

Reverse the direction of the legend:

Write a function to construct the legend as a formatted table:

LegendMarkers  (4)

By default, squares are drawn:

Use ChartElementData to construct legend markers:

Use Graphics to construct legend markers:

Use Image to construct legend markers:

LegendMarkerSize  (3)

Change the size of legend items:

Change width and height differently:

Change sizes individually:

Applications  (1)

Legend a Graph object:

Wolfram Research (2012), SwatchLegend, Wolfram Language function, https://reference.wolfram.com/language/ref/SwatchLegend.html.

Text

Wolfram Research (2012), SwatchLegend, Wolfram Language function, https://reference.wolfram.com/language/ref/SwatchLegend.html.

CMS

Wolfram Language. 2012. "SwatchLegend." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SwatchLegend.html.

APA

Wolfram Language. (2012). SwatchLegend. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SwatchLegend.html

BibTeX

@misc{reference.wolfram_2023_swatchlegend, author="Wolfram Research", title="{SwatchLegend}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/SwatchLegend.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_swatchlegend, organization={Wolfram Research}, title={SwatchLegend}, year={2012}, url={https://reference.wolfram.com/language/ref/SwatchLegend.html}, note=[Accessed: 19-March-2024 ]}