5
$\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$
  • $\begingroup$ I don't understand. Have you tried to follow the syntax of SwatchLegend? $\endgroup$ – Kuba Nov 25 '15 at 15:21
  • $\begingroup$ @Kuba: Do you mean that it just suffices to see the documentation of SwatchLegend? $\endgroup$ – Dimitris Nov 25 '15 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 Nov 26 '15 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 Nov 26 '15 at 6:59
  • $\begingroup$ P.s. but ofc I do not mind reopening, that's a part of this system $\endgroup$ – Kuba Nov 26 '15 at 7:03
6
$\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$
9
$\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$
  • $\begingroup$ Nice and easy! Thanks! $\endgroup$ – Dimitris Nov 25 '15 at 18:03
8
$\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$
  • $\begingroup$ Thanks a lot! I was sure I would get many answers:-)! $\endgroup$ – Dimitris Nov 25 '15 at 18:04
7
$\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$
  • $\begingroup$ Thanks a lot! All the answers I received are great! $\endgroup$ – Dimitris Nov 25 '15 at 18:05

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.