5
$\begingroup$

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}}]
$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – bill s
    Sep 12, 2016 at 1:13
  • $\begingroup$ @bill s Yes... I understand. However, I would like to keep the space visible with no points visible. $\endgroup$
    – B flat
    Sep 12, 2016 at 1:15

2 Answers 2

4
$\begingroup$

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 -> Charting`get3DPlotRange@plot, 
   PlotRangePadding -> None, Options[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 -> Charting`get3DPlotRange@plot, 
     PlotRangePadding -> None, Options[plot]]
    ]
  ],
 {{b, True, "points"}, {True, False}}]
$\endgroup$
3
$\begingroup$

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

enter image description here

$\endgroup$

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.