Drawing outside of 3D plot area

I have some grid-lines I want to extend outside of the bounding box of 3D plot BarChart3D. I do want to keep the bounding box small, as I want the automatic axes on the bounding box edge remain next to data.

In case of 2D plots ImagePadding does the trick. In Plot3D it does not. Here is an example.

ρ = 1/2 ({{1, 0, 0, -1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {-1, 0, 0, 1}});
Show[{
BarChart3D[ρ, BarSpacing -> {1, 1}, ChartLayout -> "Grid",
FaceGrids -> None, Method -> {"Canvas" -> None},
PlotRange -> {{-1, 8}, {-1, 8}, {-0.5, 0.5}}, Boxed -> True,
FaceGrids -> None, Axes -> {True, True, True},
ViewPoint -> {1, -5, 3},
Ticks -> {Range[-10, 10, 2], Range[-10, 10, 2],
Range[-10, 10, 2]}],
Graphics3D[{Table[Text[y, {10, y 2 - 1.5, 0}], {y, 1, 4}],
Table[Line[{{-4, y 2 - 1.5, 0}, {20, y 2 - 1.5, 0}}], {y, 1,
4}]}]}, PlotRangeClipping -> False, ImagePadding -> All
]

If I add PlotRange->All I see, that the manual grid lines were clipped. I want the long lines, but BoundingBox tightly around the bars.

There exists a trivial solution for same problem for 2D plots: Drawing outside Plot area

I do expect, there is a solution, which does not require re-implementation of axes, face grids and other features.

• There was an answer, where the axes and bounding box were manually implemented. The author deleted it. Although I was looking for a way of avoiding re-implementation of Mathematica built in features the answer should remain, as might lead another reader. Someone should recover the answer if possible.
– Johu
Commented Jan 19, 2016 at 11:15
• I deleted it because I thought it didn't answer the question, but I put it back... Commented Jun 25, 2016 at 3:42

1 Answer

Here is one way to do it. The strategy is to create our own bounding box Graphics3D object, and then give all the important options to Show instead of BarChart3D

Module[{barchart, linesandlabels, box},
barchart =  BarChart3D[\[Rho], BarSpacing -> {1, 1},
ChartLayout -> "Grid",
FaceGrids -> None,
Method -> {"Canvas" -> None} ];
linesandlabels = Graphics3D[{
Table[Text[y, {10, y 2 - 1.5, 0}], {y, 1, 4}],
Table[Line[{{-4, y 2 - 1.5, 0}, {20, y 2 - 1.5, 0}}], {y, 1, 4}]}];
box = Graphics3D[{Directive[
FaceForm[None],
EdgeForm[Black]],
Cuboid[{-1, -1, -.5}, {8, 8, .5}]}];
Show[barchart, linesandlabels, box,
Boxed -> False,
Axes -> True,
Ticks -> {Range[-10, 8, 2], Range[-10, 8, 2],
Range[-10, 10, 2]},
PlotRange -> {{-1, 20}, {-1, 8}, {-0.5, 0.5}},
AxesOrigin -> {-1, -1, -.5},
AxesStyle -> Opacity[0],
TicksStyle -> Opacity[1]
]
]

This feels like a bit of a kludge, but works for this situation. If you want to do it more generally, we could possibly make a plotting function out of it.

• +1 for the effort, but implementing the axes manually was exactly, what I though I should be able to avoid.
– Johu
Commented Jan 18, 2016 at 17:33