4
$\begingroup$

How do you use PlotLegends together with Graphics3D? The following code does not work.

  plot = Plot3D[{Sin[x y], Cos[x y]}, {x, 0, Pi}, {y, 0, Pi}, 
  AxesLabel -> Automatic, RotationAction -> "Clip", 
  PlotLegends -> "Expressions"]
  Graphics3D[plot[[1]], Axes -> True, PlotRange -> All]
$\endgroup$
  • $\begingroup$ PlotLegends is an option for plot functions that specifies what legends to use. it is not an option for Graphics3D as you can see by Options[Graphics3D, "PlotLegends"] $\endgroup$ – Martin Rommel May 8 '17 at 14:21
  • $\begingroup$ @MartinRommel then how would you achieve what I want to do? $\endgroup$ – Andrea G May 8 '17 at 14:23
3
$\begingroup$

Something like this?

plot = Plot3D[{Sin[x y], Cos[x y]}, {x, 0, Pi}, {y, 0, Pi}, AxesLabel -> Automatic, 
               RotationAction -> "Clip", PlotStyle -> {Red, Green}];

Legended[Graphics3D[plot[[1]], Axes -> True, PlotRange -> All], 
 SwatchLegend[{Red, Green}, {"sin(xy)", "cos(xy)"}]]

enter image description here

$\endgroup$
2
$\begingroup$

The simplest answer is to use Show which automatically passes the graphics options into Graphics(3D), e.g.

Show[plot, Axes -> True, PlotRange -> All, ViewPoint -> Front]

enter image description here

with ViewPoint -> Front added to improve the visual distinction with the original.

$\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.