6
$\begingroup$

How can I combine multiple SwatchLegends? As a minimal example:

Legended[
  Show[g1 = Graphics3D[{Opacity[0.6], Red, Sphere[]}]], 
    SwatchLegend[{Red, Red, Red}, {"x\[Rule]ξ", "y\[Rule]η", "z≡ζ"}]]

enter image description here

Legended[
  Show[g2 = Graphics3D[{Opacity[0.4], Blue, Cylinder[]}]], 
    SwatchLegend[{Blue, Blue, Blue}, {"ξ≡ξ'", "η\[Rule]η'", "ζ\[Rule]ζ'"}]]

enter image description here

Legended[
  Show[g3 = Graphics3D[{Green, Cone[]}]], 
    SwatchLegend[{Green, Green, Green}, {"ξ'\[Rule]x'", "η'\[Rule]y'", "ζ'≡z'"}]]

enter image description here

Now I would like to combine them; something like

Legended[
  Show[{g1, g2, g3}], 
    SwatchLegend[{
      {Red, Red, Red}, {"x\[Rule]ξ", "y\[Rule]η", "z≡ζ"}, 
      {Blue, Blue, Blue}, {"ξ≡ξ'", "η\[Rule]η'", "ζ\[Rule]ζ'"}, 
      {Green, Green, Green}, {"ξ'\[Rule]x'", "η'\[Rule]y'", "ζ'≡z'"}}]]

enter image description here

does not work.

I failed to find a duplicate.

$\endgroup$
6
  • $\begingroup$ I don't understand. Have you tried to follow the syntax of SwatchLegend? $\endgroup$
    – Kuba
    Commented Nov 25, 2015 at 15:21
  • $\begingroup$ @Kuba: Do you mean that it just suffices to see the documentation of SwatchLegend? $\endgroup$
    – Dimitris
    Commented Nov 25, 2015 at 15:53
  • 2
    $\begingroup$ I am voting to reopen this question because I think it a bad idea to close an up-voted question with five good answers just because it is possible for a highly experienced Mathematica user can work out a solution by reading the docs. $\endgroup$
    – m_goldberg
    Commented Nov 26, 2015 at 1:04
  • $\begingroup$ @m_goldberg sorry but I do not agree with your reopen reason. Could you elaborate why only highly experienced users are able to follow the syntax presented in usage section? I may have misssed something in this question, then Im sorry. But i really can't see a deeper bottom here. No I look like a bully ;) $\endgroup$
    – Kuba
    Commented Nov 26, 2015 at 6:59
  • $\begingroup$ P.s. but ofc I do not mind reopening, that's a part of this system $\endgroup$
    – Kuba
    Commented Nov 26, 2015 at 7:03

4 Answers 4

7
$\begingroup$

To avoid redundant color swatches:

g1 = Graphics3D[{Opacity[0.6], Red, Sphere[]}];
g2 = Graphics3D[{Opacity[0.4], Blue, Cylinder[]}];
g3 = Graphics3D[{Green, Cone[]}];

Legended[Show[g1, g2, g3],
 SwatchLegend[
  {Red, Blue, Green},
  {Column[{"", "x\[Rule]ξ", "y\[Rule]η", 
     "z≡ζ", ""}],
   Column[{"", "ξ≡ξ'", "η\[Rule]η'", 
     "ζ\[Rule]ζ'", ""}],
   Column[{"", "ξ'\[Rule]x'", "η'\[Rule]y'", 
     "ζ'≡z'", ""}]}]]

enter image description here

$\endgroup$
10
$\begingroup$

Show already combines these if you include the legends in your assignments.

x1 = Legended[Show[Graphics3D[{Opacity[0.6], Red, Sphere[]}]], 
  SwatchLegend[{Red, Red, Red}, {"x\[Rule]ξ", "y\[Rule]η", "z≡ζ"}]];

x2 = Legended[Show[Graphics3D[{Opacity[0.4], Blue, Cylinder[]}]], 
  SwatchLegend[{Blue, Blue, Blue}, {"ξ≡ξ'", "η\[Rule]η'", "ζ\[Rule]ζ'"}]];

x3 = Legended[Show[Graphics3D[{Green, Cone[]}]], 
  SwatchLegend[{Green, Green, Green}, {"ξ'\[Rule]x'", "η'\[Rule]y'", "ζ'≡z'"}]];

Now simply:

Show[x1, x2, x3]

enter image description here

$\endgroup$
1
  • $\begingroup$ Nice and easy! Thanks! $\endgroup$
    – Dimitris
    Commented Nov 25, 2015 at 18:03
9
$\begingroup$

you can also do it like this:

Legended[Show[{g1, g2, g3}], 
 Grid[{SwatchLegend @@@ {{{Red, Red, Red}, {"x\[Rule]ξ", "y\[Rule]η", "z≡ζ"}}, 
  {{Blue, Blue, Blue}, {"ξ≡ξ'", "η\[Rule]η'", "ζ\[Rule]ζ'"}}, 
  {{Green, Green, Green}, {"ξ'\[Rule]x'", "η'\[Rule]y'", "ζ'≡z'"}}}}]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks a lot! I was sure I would get many answers:-)! $\endgroup$
    – Dimitris
    Commented Nov 25, 2015 at 18:04
8
$\begingroup$
Legended[Show[{g1, g2, g3}], 
 SwatchLegend[{RGBColor[1, 0, 0], RGBColor[0, 0, 1], RGBColor[0, 1, 0], RGBColor[1, 0, 0], 
   RGBColor[0, 0, 1], RGBColor[0, 1, 0], RGBColor[1, 0, 0], RGBColor[0, 0, 1], 
   RGBColor[0, 1, 0]}, 
  {"x\[Rule]ξ", "ξ≡ξ'", "ξ'\[Rule]x'", "y\[Rule]η", "η\[Rule]η'",  "η'\[Rule]y'", "z≡ζ", 
   "ζ\[Rule]ζ'", "ζ'≡z'"}, 
  LegendLayout -> {"Row", 3}]]

Row

Or

Legended[Show[{g1, g2, g3}], 
 SwatchLegend[{RGBColor[1, 0, 0], RGBColor[0, 0, 1], RGBColor[0, 1, 0], RGBColor[1, 0, 0], 
    RGBColor[0, 0, 1], RGBColor[0, 1, 0], RGBColor[1, 0, 0], RGBColor[0, 0, 1], 
    RGBColor[0, 1, 0]}, 
   {"x\[Rule]ξ", "ξ≡ξ'", "ξ'\[Rule]x'", "y\[Rule]η", "η\[Rule]η'", "η'\[Rule]y'", 
    "z≡ζ", "ζ\[Rule]ζ'", "ζ'≡z'"}, 
  LegendLayout -> {"Column", 3}]]

Column

$\endgroup$
1
  • $\begingroup$ Thanks a lot! All the answers I received are great! $\endgroup$
    – Dimitris
    Commented Nov 25, 2015 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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