Hot answers tagged

7

It looks like kglr beat me to it but I was also working on a LegendLayout method, so here it is. styles = {Red, {Red, Dashed}, Blue, {Blue, Dashed}}; pair = (Grid[{Column @ #[[All, 1]], #[[1, 2]]} & /@ Partition[#, 2]] &); Plot[{x^2, 1/x^2, 2 x^2, 2/x^2}, {x, 0, 3}, Frame -> True, PlotStyle -> styles, PlotLegends -> LineLegend[...


7

ClearAll[table] table[pairs_] := Module[{p = pairs}, p[[3, 2]] = SpanFromAbove; p[[4, 2]] = SpanFromAbove; Grid[p[[{1, 3, 2, 4}]], Alignment -> {Center, Center}]]; styles = {Red, Blue, {Red, Dashed}, {Blue, Dashed}}; pt1 = Plot[{x^2, 2 x^2, 1/x^2, 2/x^2}, {x, 0, 3}, Frame -> True, PlotStyle -> styles, PlotLegends -> LineLegend[...


5

Actually the answer is already given in the documentation for SwatchLegend. All you need to do is to wrap Legended around the Show: Legended[ Show[ plot1, plot2, PlotRange -> All ], SwatchLegend[ {Red, Yellow}, {"A", "B"} ] ] Note: Should the legend become larger and is entered by hand, using Transpose may make this easier, e.g. SwatchLegend @@ ...


3

There are some things that bother me in Johu's solution, so I am offering this alternative, which seems both simpler and better to me. This works with versions of Mathematica older than V10. RAveList = RandomReal[1, {11, 5}]; colors = ColorData[97]; labels = Row[{#, "-clusters"}] & /@ Range[2, 12]; ListPlot[Thread[Tooltip[RAveList, labels]], Joined -&...


3

Your example has several problems, why people can not directly run it. For example you have not provided RAveList and you use it as it was a function. I assume it is an array, but the answer can be easily adjusted. Here is an example of the labels you wanted. RAveList = RandomReal[1, {25, 5}]; selection = 2 ;; 15; labels = Array[StringTemplate["``-clusters"]...


3

To extend m_goldberg's answer, the legend functions (BarLegend, LineLegend, PointLegend, and SwatchLegend) use the plot's LabelStyle, by default. So, you can set the LabelStyle for the entire plot, if you want uniformity, e.g. VectorDensityPlot[{x, -y}, {x, -5, 5}, {y, -5, 5}, PlotLegends -> BarLegend[Automatic, LegendLabel -> "Cooper Std"], ...


3

I know this is an old question, but just in case: Now in Mathematica 9.0 or higher, PlotLegends does this automatically. ListDensityPlot[ Table[Sin[j^2 + i], {i, 0, Pi, 0.02}, {j, 0, Pi, 0.02}], PlotLegends -> Automatic] Cite: Documentation


2

Use Show instead of Epilog to add on the rectangles, and the legend will stay on top. Show[ ListDensityPlot[..., PlotLegends -> ...] Graphics[{...}] ]


2

I would suggest creating the legend separately and combine with Grid. Grid[{{Show[plot1, plot2, PlotRange -> All], SwatchLegend[{Red, Yellow}, {"plot1", "plot2"}]}}]


1

Example Code ListPlot[{a, b}, Joined -> True, PlotStyle -> {Red, Yellow}, PlotLegends -> Automatic] Note: a and b are your original data lists a1 and a2 respectively. Output With SwatchLegend Code ListPlot[ {a, b}, Joined -> True, PlotStyle -> {Red, Yellow}, PlotLegends -> SwatchLegend[{"a", "b"}] ] Output With Show Code ...



Only top voted, non community-wiki answers of a minimum length are eligible