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[leg,pos]specify placement of legend
  • The following legend constructors can be used to form commonly occurring legends: SwatchLegend, LineLegend, PointLegend and BarLegend.
  • PlotLegendsPlaced[leg,pos] places the legend leg at the position specified by pos.
  • Possible forms for pos are:
  • Above,Below,Before,Afterpositions outside the bounding box for expr
    {h,v}horizontal h and vertical positions v
    {{ex,ey},{lx,ly}}scaled position {lx,ly} in the legend at scaled position {ex,ey} in expr
  • Possible horizontal positions include Before, Left, Center, Right and After.
  • Possible vertical positions include Below, Bottom, Center, Top and Above.

Examples

open allclose all

Basic Examples  (5)

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 below the plot:

Place a legend inside a 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:

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

Text

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

CMS

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

APA

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_plotlegends, organization={Wolfram Research}, title={PlotLegends}, year={2012}, url={https://reference.wolfram.com/language/ref/PlotLegends.html}, note=[Accessed: 09-December-2024 ]}