4

I have made this 3D figure: enter image description here

I want the lines to be in front of the axes. Here is the code that I used:

data1 = {{0, 0, 0}, {0.8, 0, 0}}
data2 = {{0, 0, 0}, {0, 0, 0.5}}

plot = ListLinePlot3D[{data1, data2}, AxesOrigin -> {0, 0, 0}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, BoxRatios -> {1, 1, 1}, Boxed -> False, ViewPoint -> {3, 2, 2}, Ticks -> None, AxesStyle -> Directive[Black, Thickness[.005]], PlotStyle -> {{Gray, Thickness[.05]}, {Red, Thickness[.05]}} ]; Show[plot, Method -> {"AxesInFront" -> False}]

As can be seen, I have used Show and Method -> {"AxesInFront" -> False} excerpt from this previous post . Unfortunately, it doesn't seem to work.

How can this be achieved for all the lines in the plot?

Astor Florida
  • 1,326
  • 7
  • 21

1 Answers1

4

Based on this related Q/A, it seems it is impossible to occlude axes in Graphics3D unless they are placed on box edges using AxesEdge.

In your case, a simple work-around is to use graphics primitives instead of built-in axes:

axes = Graphics3D[{Thick, InfiniteLine[{0, 0, 0}, #] & /@ IdentityMatrix[3]}];

Show[axes, plot, Axes -> False,Options[plot]]

enter image description here

Update: A more flexible approach is to define a function that extracts relevant axes options from a plot object and creates a Graphics3D object with the desired line primitives:

axes3D = Graphics3D[Flatten @ Cases[{True | Automatic, a__} :> a] @
  Thread[{#, #2, (x |-> InfiniteLine[{#3, x}]) /@ 
        (IdentityMatrix[3] + Threaded[#3])}] & @@ 
  Values @ AbsoluteOptions[#, {Axes, AxesStyle, AxesOrigin}], 
  Boxed -> False] &;

Examples:

Show[axes3D[plot], plot, Axes -> False, Options[plot]]

enter image description here

plot2 = ListLinePlot3D[{data1, data2}, 
  AxesOrigin -> {0, .5, -.25}, 
  PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, 
  BoxRatios -> {1, 1, 1}, 
  Boxed -> False, ViewPoint -> {3, 2, 2}, 
  Ticks -> None, 
  AxesStyle -> (Directive[#, Thickness[.005]] & /@ {Green, Blue, Orange}), 
  PlotStyle -> {{Gray, Thickness[.05]}, {Red, Thickness[.05]}}]

enter image description here

Show[axes3D[plot2], plot2, Axes -> False, Options[plot2]]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896