This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
How to | Make a Legend for My Plots
Mathematica provides many options for customizing and annotating plots. Legends can be added to plots and customized with many of the same methods used to customize other Mathematica graphics.
This is a selection of examples from the complete "How to" screencast. »
First, load the PlotLegends package:
Click for copyable input
Use the PlotLegend option to generate a plot with legends:
Click for copyable input
Any styling used in the plot is reflected in the legend:
Click for copyable input
The PlotLegends package can also be used to generate color bars for density and contour plots. However, this requires more effort, as well as some knowledge about the results in the plot.
ShowLegend can be used to display legends for graphics produced with DensityPlot:
Click for copyable input
Similarly, ShowLegend can be used with ContourPlot:
Click for copyable input
You can also programmatically customize your legends with options such as LegendPosition, LegendShadow, LegendBackground, LegendBorder, and ShadowBackground. Further information on doing this is presented in the full screencast.
The methods shown here will not work for adding legends to charts in Mathematica. For information on this, see How to: Make a Legend for My Charts.