PlotLegends

PlotLegends

is an option for plot functions that specifies what legends to use.

Details

  • Typical settings for PlotLegends include:
  • Noneadd no legend
    Automaticuse automatic legending
    "Expressions"use formulas as legend labels
    {lbl1,lbl2,}use lbli for the i^(th) input
    expruse expr as legend
    Placed[lspec,]specify placement of legend
  • The following legend constructors can be used to form commonly occurring legends: SwatchLegend, LineLegend, PointLegend, and BarLegend.

Examples

open allclose all

Basic Examples  (4)

Use editable placeholders as the legend for a plot:

Use the expressions being plotted as the legend:

Specify the text for a legend:

Place the legend above the plot:

Scope  (5)

Legend Content  (2)

Use LineLegend to construct a legend:

Use SwatchLegend to construct a legend:

BarLegend is used in ContourPlot and DensityPlot:

Use SwatchLegend to construct a legend:

A legend can be any expression:

Legend Placement  (3)

Use Placed to change legend placement:

Use named horizontal and vertical positions to place a legend:

Use scaled coordinates associated with plot range to place a legend:

For fine-control legend placement, specify the position where a legend should be placed:

Possible Issues  (1)

Control variables in Manipulate are shown in legend with full context due to the HoldForm:

Use With to show the variable value:

Introduced in 2012
 (9.0)