2
$\begingroup$

I would like to display the labels of a 3D plot (made of many subplots) as a column at the bottom of the plot. I managed to put them at the bottom, thanks to the option Placed, but they are always displayed in a row. How can I put them in column?

Here is a minimal working example. The actual code is much more lengthy.

test1 = Quiet@ParametricPlot3D[{u, 0, 0}, {u, 0, 1}, PlotLegends -> Placed[{"test1"}, Bottom]];
test2 = Quiet@ParametricPlot3D[{0, u, 0}, {u, 0, 1}, PlotLegends -> Placed[{"test2"}, Bottom]];
test3 = Quiet@ParametricPlot3D[{0, 0, u}, {u, 0, 1}, PlotLegends -> Placed[{"test3"}, Bottom]];
Show[test1, test2, test3]

I want the labels to be displayed as a column opposed as a row

The overall structure is fixed (I cannot plot test1, test2 and test3 as a single plot but I have to merge them through Show).

Thank you.

$\endgroup$
1
$\begingroup$

You can extract the graphics and the legends from the output of Show and reorganize the legends as follows:

test1 =   ParametricPlot3D[{u, 0, 0}, {u, 0, 1}, PlotStyle -> Red, 
       PlotLegends -> Placed[{"test1"}, Bottom]];
test2 =   ParametricPlot3D[{0, u, 0}, {u, 0, 1}, PlotStyle -> Blue, 
       PlotLegends -> Placed[{"test2"}, Bottom]];
test3 =  ParametricPlot3D[{0, 0, u}, {u, 0, 1}, PlotStyle -> Green, 
       PlotLegends -> Placed[{"test3"}, Bottom]];
show = Show[test1, test2, test3];
graphics = show[[1, 1, 1]];
legend = Column[SortBy[Cases[show, Placed[a_, __] :> a, {0, Infinity}], #[[2, 1]] &]];

Legended[graphics, Placed[legend, Bottom]] (* or *)
Labeled[graphics, legend]

enter image description here

$\endgroup$
1
  • $\begingroup$ This answer, although more convoluted, is working perfectly in the real case. $\endgroup$ – LastStarDust Apr 28 '18 at 3:24
1
$\begingroup$

Something like this?

Legended[
  Show[
    Plot3D[Sin[ x] + Cos[ y], {x, 0, 2 π}, {y, 0, 2 π}, PlotStyle -> Red],
    Plot3D[Sin[ x] - Cos[ y], {x, 0, 2 π}, {y, 0, 2 π}, PlotStyle -> Blue]],
 Placed[LineLegend[{Red, Blue}, {"test1", "test2"}], Below]]

plot

$\endgroup$
2
  • $\begingroup$ Thank you. I have chosen your solution because is neater, anyway, also the answer from @kglr is working. $\endgroup$ – LastStarDust Apr 28 '18 at 1:55
  • $\begingroup$ EDIT: in the real case is not working as expected. Not for a flaw in the answer but for the pecularity of the real case. $\endgroup$ – LastStarDust Apr 28 '18 at 3:24

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.