Questions tagged [legending]

Questions on legends, figures (usually insets) that indicate what those lines/bars/points in plots refer to, using arrangements of graphic elements and text, whether manually or using built-in functions.

Mathematica provides built-in Legend functionality for charting functions such as BarChart and PieChart. For plotting functions such as Plot, ListPlot and DateListPlot, the PlotLegends` package is available. However it is slow and difficult to customise. The ShowLegend function provided by that package offers a little more control. Generally, however, both performance and aesthetics are better if one uses a custom function such as this one.

Please consider using one of the tags or according to whether your question is about 2D or 3D graphics.

Useful links:

Example questions:

900 questions
34
votes
2 answers

Poets of the 19th century

fun[p_] := Module[{per, bd, dd}, per = Interpreter["Person"][p]; bd = DateValue[PersonData[per, "BirthDate"], "Year"]; dd = DateValue[PersonData[per, "DeathDate"], "Year"]; Range[bd, dd]] names = {"Napoleon Bonaparte", "Jane Austen",…
eldo
  • 67,911
  • 5
  • 60
  • 168
21
votes
2 answers

How to raise the LegendLayout "Row" size

When using LegendLayout->"Row", with a lengthy row, I get line breaks. This would seemed logic if it was confined by another structure. But if happens even when there's no "confinement": LineLegend[{Blue, Orange, Green}, {"this is a big test", …
P. Fonseca
  • 6,665
  • 2
  • 28
  • 60
21
votes
2 answers

Changing the inter-item spacing in Legends (version 9 and up)

The legending functionality in versions 9 and higher is much easier to use than the PlotLegends package and other bespoke ways of creating legends in earlier versions. However, the vertical spacing between items is larger than I would like. How can…
Verbeia
  • 34,233
  • 9
  • 109
  • 224
15
votes
2 answers

Learning curve for Mathematica

May be some of you (moderators and custodians) would discard this question as opinion-based and requiring discussion, but I didn't want the effort to go to waste so felt compelled to ask. Please feel free to shut down/migrate/ignore this…
Syed
  • 52,495
  • 4
  • 30
  • 85
14
votes
1 answer

How to change the spacing of line in legend?

Given this plot: ListLinePlot[ { berea[[All, {1, 2}]] , beryl[[All, {1, 2}]] , graphite[[All, {1, 2}]] , nb[[All, {1, 2}]] , nu0[[All, {1, 2}]] , nunim[[All, {1, 2}]] } , Filling -> {5 -> {6}} , Frame -> True , FrameLabel -> { …
Ali Ordookhani
  • 141
  • 1
  • 4
9
votes
2 answers

Why does not BarLegend accept user-defined color function?

I encountered a really strange problem with BarLegend. Say you have a user-defined color function: cf[z_]:=RGBColor[RandomReal[z, 3]] When you want to use it in BarLegend as below: BarLegend[{cf, {1, 10}}] Mathematica will generate a blank bar…
sunt05
  • 4,367
  • 23
  • 34
9
votes
2 answers

How to control the padding below a BarLegend?

BarLegend has an annoyingly large space at the bottom. I can see that this was added to make it line up with the frame of the plot when there is a bottom frame label (see e.g. here), but this does not work out well for all plot sizes, and it causes…
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
9
votes
1 answer

LineLegend is behaving erratically

The top one is fine, but if I change Red into dashed version, it behaves erratically.
Wendy
  • 141
  • 4
8
votes
1 answer

Specify legend position in a plot

I would like to place the legend inside the plot frame. I have been doing a search in the documentation but only found option ChartLegends -> Placed[{"label", {Center}] Other options, such as Up, Bottom, Right, place the label outside. How can I…
user1993416
  • 589
  • 1
  • 5
  • 12
7
votes
2 answers

How To Span Table Headings?

What I am doing wrong? I would like to get a header to the table and based on your code I tried this: hdr = {{"Calculated Coordinates", SpanFromLeft}, {"No", "x", "y"}}; hdr1 = Grid[hdr, Frame -> All]; legendmarkers=Range@Length@data;
 …
Harald
  • 1,573
  • 1
  • 11
  • 15
6
votes
2 answers

Change the legend labels' font when PlotLegends is Automatic

I am using the options PlotTheme -> "Scientific" and PlotLegends -> Placed[Automatic, Right] on a MatrixPlot and I would like to change the font size of the legend labels. I would usually do that by specifying BarLegend[{"LakeColors", {0, 1}},…
Sulli
  • 2,185
  • 14
  • 28
6
votes
3 answers

How to use LineLegend and SwatchLegend together

I am wondering if one can place on the right of the plot frame a single legend that is a combination of a LineLegend and a SwatchLegend. What I want is to see the line with its label on top of the swatch with its label as if the swatch was the…
Rho Phi
  • 1,420
  • 11
  • 21
6
votes
1 answer

Legend for ListContourPlot

Consider this example below for ListContourPlot. ListContourPlot[ Table[Sin[j^2 + i], {i, 0, Pi, 0.02}, {j, 0, Pi, 0.02}], PlotLegends -> Automatic] I wish to make the Legend look like this: I have searched the net but did not find any way of…
Hubble07
  • 3,614
  • 13
  • 23
6
votes
1 answer

Can I add legends to a SmoothHistogram?

Under the options menu for Histogram, there is an option called ChartLegends, which adds little boxes beside the plot to indicate which curve represents what. I cannot find a similar option for SmoothHistogram. I know that PlotLegends is new in…
cartonn
  • 1,005
  • 6
  • 15
5
votes
1 answer

Wrong BarLegend with VisibleSpectrum

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, ColorFunction -> (ColorData["VisibleSpectrum"][ Rescale[#3, {0, 1}, {380, 750}]] &), PlotLegends -> Automatic] There is no legend in this picture. Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2,…
Apple
  • 3,663
  • 16
  • 25
1
2 3 4 5