# How to get axes behind plot lines in ListLinePlot3D?

I have made this 3D figure:

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?

• related Q/A
– kglr
Commented May 9, 2023 at 17:56

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]]


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]]


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]}}]


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


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