2
$\begingroup$

I have used ListLinePlot to generate this grid of plots:

enter image description here

and I want to add a legend in Row Layout below this grid. My code, has as follows:

graphs = Table[
   ListLinePlot[
    Table[Transpose@{vdd, power[[i, j, All]]}, {j, 1, Wl}],
    PlotLabel -> "T=" <> ToString[T[[i]]] <> "\[Degree]C",
    Frame -> {{True, False}, {True, False}},
    FrameLabel -> {"\!\(\*SubscriptBox[\(V\), \(DD\)]\)(V)","P(nW)"},
    AspectRatio -> 1/GoldenRatio,
    ImageSize -> Medium
    ],
   {i, 1, Tl}];
a = {graphs[[1 ;; 3]], graphs[[4 ;; 6]]};
grid = GraphicsGrid[a, Spacings -> Scaled[0], 
   AspectRatio -> 0.6/GoldenRatio];

where vdd[[...]], W[[...]], T[[...]],power[[...,...,...]] are lists with the measured values and each colored curve in the above plots, corresponds for a different (but known) value of W.

I was thinking to use

Column[{grid, 
  LineLegend[{...colors...}, Table[ToString[W[[n]]]<>"nm",{n,1,Wl}], 
   LegendLayout -> "Row"]}]

but I cannot generate the default colour pallete, which Mathematica uses. Also, I need the legend to be justified to the center (presentation purposes, as you can see).

Any help please?

$\endgroup$
  • 1
    $\begingroup$ Default colors: ColorData[1, "ColorList"]. $\endgroup$ – kglr Apr 16 '14 at 20:57
  • $\begingroup$ Thank you kguler. Column[{grid, LineLegend[ColorData[1, "ColorList"], Table[ToString[Round@W[[n]]] <> "nm", {n, 1, Wl}], LegendLayout -> "Row"]}] . The problem now is that the legend entries are not in one row and they are not justified. Anyway great help in so little time! $\endgroup$ – jojosthegreat Apr 16 '14 at 21:20
  • $\begingroup$ LineLegend[1, labels,...] is the shorter version of LineLegend[ColorData[1,"ColorList"], labels, ...]. To prevent line-wrapping you can use something like LineLegend[1, labels, LegendLayout -> (Pane[Row[Flatten@#, Spacer[3]], 1200] &)] or LineLegend[1, labels, LegendLayout -> (Pane[Grid[{Flatten@#}], 1200] &)]. $\endgroup$ – kglr Apr 17 '14 at 2:56
2
$\begingroup$

I guess this could be solved by

defcol[n_] := ColorData[1, "ColorList"][[n]];
Legended[Plot[{Sin[x], Sin[x]^2, Cos[x]}, {x, -2 \[Pi], 2 \[Pi]}],
 Placed[LineLegend[
   {defcol[1], defcol[2], defcol[3]},
   {"S", "S2", "C"},
   LegendLayout -> "Row"], {0.5, -0.1}]]

enter image description here

The position of Legend is defined by option {0.5, -0.1}

This could be applied for any combination of graphical objects, so in your case put Legended around your GraphicsGrid

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.