BarLegend
BarLegend[cf] generates a legend that identifies colors from the color function cf with an automatic range of values.
BarLegend[{cf, {min, max}}] generates a legend that identifies colors from the color function cf with the range of values between min and max.
BarLegend[cf, n] limits the number of ticks shown on the legend to n.
Options
LegendLabeladds a label to the legend.LegendLayout -> "Row"displays the color bar horizontally.LabelStylestyles the legend label and tick labels. Colors,FontFamily, andFontSizeare supported.ImageSizesets the size of the color bar; use a two-element list to align the legend height with a plot.
Examples
Create a color bar legend:
BarLegend["Rainbow"]With specified range:
BarLegend[{"TemperatureMap", {0, 100}}]Add a label and limit the number of ticks:
BarLegend["Thermometer", 3,
LegendLabel -> "Temperature",
LabelStyle -> Directive[FontSize -> 14]
]Create a horizontal bar and move its label by an absolute offset:
BarLegend[
{"Rainbow", {0, 1}},
2,
LegendLayout -> "Row",
ImageSize -> {300, 20},
LegendLabel -> {"Temperature", {0, -35}}
]Align a bar legend with a plot:
ContourPlot[
(x^2 - y^2)/(x^2 + y^2)^2,
{x, -1, 1}, {y, -1, 1},
Contours -> 4,
PlotLegends -> BarLegend[Automatic, ImageSize -> {20, 300}],
ImageSize -> {300, 300},
ColorFunction -> "Rainbow",
ClippingStyle -> Automatic
]Something isn't working? Report an issue.
Please visit the official Wolfram Language Reference for more details.