# How to Toggle Points on and Off

The code below is a snippet of some large code that I am working on. I want the points in the code below to appear and disappear when selecting the toggle box "points". I do not want to use the opacity or flipview techniques found here. They are not optimal when used with the rest of my code. I tried the following and used "" as in the same link above... but it doesn't work. Any suggestions?

Manipulate[
ListPointPlot3D[
If[b, {{0, 0, 3}, {0, 3, 0}, {3, 0, 0}, {0, 0, -3}, {0, -3, 0}, {-3,
0, 0}}, ""]],
{{b, True, "points"}, {True, False}}]

• If you put some points instead of "" then it flips fine. The problem is you have to make ListPlot3D happy by giving it something to plot. Sep 12, 2016 at 1:13
• @bill s Yes... I understand. However, I would like to keep the space visible with no points visible. Sep 12, 2016 at 1:15

I'm surprised that ListPointPlot3D[{}, PlotRange -> ...] does not work. ListPlot[{}] works and so should ListPointPlot3D, I think.

An OK solution: You have to be able to calculate the plot range though.

Manipulate[
If[b,
plot = ListPointPlot3D[{{0, 0, 3}, {0, 3, 0}, {3, 0, 0}, {0,
0, -3}, {0, -3, 0}, {-3, 0, 0}}],
Graphics3D[{}, PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}},
Options[plot]]
],
{{b, True, "points"}, {True, False}},
{plot, ControlType -> None}]


There's a slight wiggle because Options[plot] does not give the correct padding for the vertical axis.

This works perfectly, but uses an undocumented function:

Manipulate[
If[b,
plot = ListPointPlot3D[{{0, 0, 3}, {0, 3, 0}, {3, 0, 0}, {0,
0, -3}, {0, -3, 0}, {-3, 0, 0}}],
Graphics3D[{}, PlotRange -> Chartingget3DPlotRange@plot,
],
{{b, True, "points"}, {True, False}},
{plot, ControlType -> None},
TrackedSymbols :> {b}]


The TrackedSymbols options does not seem to be necessary in this simple example, but it might be in a more complicated application.

Slightly more efficient, if the code structure of the actual use-case allows for it:

data = RandomReal[{-3, 3}, {10000, 3}];
Manipulate[
With[{plot = ListPointPlot3D[data]},
Dynamic@ If[b,
plot,
Graphics3D[{}, PlotRange -> Chartingget3DPlotRange@plot,
]
],
{{b, True, "points"}, {True, False}}]


Does this work for you?

b = True;
pts = {{0, 0, 3}, {0, 3, 0}, {3, 0, 0}, {0, 0, -3}, {0, -3, 0}, {-3,
0, 0}};
l = ListPointPlot3D@pts;
Dynamic[p = If[b, pts, {{0, 0, 20}}];
Checkbox[Dynamic[b], {False, True}]]
Dynamic@Quiet@
ListPointPlot3D[p, PlotRange -> MinMax /@ Transpose@pts,
PlotRangePadding -> Scaled[.1], PlotTheme -> "Marketing"]