4
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ related Q/A $\endgroup$
    – kglr
    Commented May 9, 2023 at 17:56

1 Answer 1

4
$\begingroup$

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

$\endgroup$
2
  • 2
    $\begingroup$ Adding Ticks is a huge challenge. $\endgroup$
    – kglr
    Commented May 9, 2023 at 19:38
  • $\begingroup$ for a quick-and-dirty-custom-3dticks see this answer $\endgroup$
    – kglr
    Commented May 10, 2023 at 9:10

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.