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.
Styling options
SwatchLegend supports LegendFunction, LegendLayout, LegendMargins, LabelStyle, RoundingRadius, and Background.
LegendFunctionaccepts the named functions"Panel","Frame","Framed","DarkFrame", and"Frameless". Arbitrary functions are not currently supported.LegendLayoutaccepts"Row","Column","ReversedRow", and"ReversedColumn".LegendMarginsaccepts either one margin for every side or{{left, right}, {top, bottom}}.LabelStylesupports colors,FontFamily, andFontSize.RoundingRadiussets the corner radius of the legend container.Backgroundsets the container background.
These options are also supported by LineLegend and PointLegend.
Examples
Create a color swatch legend:
SwatchLegend[{Red, Green, Blue}, {"Low", "Medium", "High"}]Use with a plot:
BarChart[{1, 2, 3}, ChartLegends -> SwatchLegend[{"A", "B", "C"}]]Combine layout and container styles:
Plot[{x, 2x}, {x, 0, 1},
PlotLegends -> Placed[
SwatchLegend[Automatic, {"x", "2x"},
LegendFunction -> "DarkFrame",
LegendLayout -> "Row",
LegendMargins -> {{5, 9}, {5, 5}},
LabelStyle -> Directive[FontSize -> 12],
RoundingRadius -> 0,
Background -> White
],
{0.45, 0.5}
]
]Something isn't working? Report an issue.
Please visit the official Wolfram Language Reference for more details.