2
$\begingroup$

I am trying to position the legend in a 3D graphics using PlotLegend[Placed... If I do this, I am not able to rotate the 3D graphics. The default legend location is a little too far from the graphics box, so I want to place it differently. Is there someway of doing this while preserving the rotation viewing function?<

list1 = {2, 3, 4, 6, 7, 1, 5};
list2 = {3, 2, 1, 5, 6, 7, 4};

data1 = {{250, 0.0001`, 0.17`}, {276, 0.000085`, 0.17`}, {381, 
0.000094`, 0.13`}, {306, 0.000072`, 0.14`}, {310, 0.00005`, 
0.1`}, {283, 0.00011`, 0.16`}, {291, 0.00008`, 0.23`}}
data2 = {{123, 0.00061`, 0.25`}, {130, 0.000055`, 0.046`}, {90, 
0.00071`, 0.27`}, {115, 0.00012`, 0.26`}, {103, 0.00032`, 
0.48`}, {109, 0.0012`, 0.24`}, {101, 0.00063`, 0.28`}}
testplot = 
ListPointPlot3D[{data1 -> list1, data2 -> list2}, 
PlotRange -> {{80, 400.}, {0, .0015}, {0, .8}}, 
PlotStyle -> (Directive[PointSize[.02], Opacity[2.8], 
   AbsoluteThickness[3.0], #] & /@ {Hue[0.58, 1, 1], 
  Hue[0., 1, 1], Hue[0.58, 1, 1], Hue[1., 1, .0], 
  Hue[0.8, .8, .5], Hue[1., 0.5, 1.]}), 
LabelStyle -> Directive[Bold, FontSize -> 12, FontColor -> Black], 
 PlotLegends -> 
 Placed[LineLegend[{"data1 ", "data2"}, LegendLabel -> " ", 
 LabelStyle -> {Helvetica, Bold, 12}], {{1, 1}, {1, 1}}], 
 AxesLabel -> {" xtest name", "y testname", 
 Rotate["ztestname", Pi/2]}, 
 PlotLabel -> Style["", FontSize -> 12, FontColor -> Black], 
 FaceGrids -> {{0, 0, -1}, {-1, 0, 0}, {0, 1, 0}}, 
 ViewAngle -> 30*Degree]
 test3d = Graphics3D[{Opacity[.2], Blue, 
 InfinitePlane[{{1, 0, .21}, {0, 1, .21}, {0, 0, .21}}]}]
Show[testplot, test3d, SphericalRegion -> True]
$\endgroup$

1 Answer 1

5
$\begingroup$

You can use Labeled to add the legend as a label:

Labeled[Show[testplot[[1]], test3d, SphericalRegion -> True], testplot[[2, 1]], 
 {{Top, Right}}, 
 FrameMargins -> {{0, 0}, {0, -100}}]

enter image description here

Note: The first part of testplot (that is, testplot[[1]]) contains the 3D graphics object and the second part contains the legend wrapped in Placed:

testplot[[2]]

enter image description here

$\endgroup$

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.