3
$\begingroup$

Why does ListPointPlot3D accept tables with 3 outputs and 2 variables such as:

Table[{a,b,1},{a,-1,1},{b,-1,1}]
ListPointPlot3D[Table[{a,b,1},{a,-1,1},{b,-1,1}]]

but doesn't accept tables with 3 outputs and 3 variables?

Table[{a,b,c},{a,-1,1},{b,-1,1},{c,-1,1}]
ListPointPlot3D[Table[{a,b,c},{a,-1,1},{b,-1,1},{c,-1,1}]]

Am I doing something wrong or is Mathematica stupid?

$\endgroup$
4
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. The introductory book written by the inventor is a good learning resource. There is a fast intro for math students as well as a fast intro for programmers to choose from. $\endgroup$
    – Syed
    Jun 16 at 14:34
  • 2
    $\begingroup$ Try: t2 = Flatten[Table[{a, b, c}, {a, -1, 1}, {b, -1, 1}, {c, -1, 1}], 2] and ListPointPlot3D[t2] OR t3 = Flatten[Table[{a, b, c}, {a, -1, 1}, {b, -1, 1}, {c, -1, 1}], 1] and ListPointPlot3D[t3]. $\endgroup$
    – Syed
    Jun 16 at 14:36
  • $\begingroup$ Ah that works altho I dont understand why. Thanks $\endgroup$
    – J. Pruim
    Jun 16 at 14:46
  • 2
    $\begingroup$ Run Dimensions on the outputs of your Table expressions to see the structure of the lists being generated, and compare those with the allowable inputs for ListPointPlot3D mentioned in the documentation. As an alternative to your second example, consider Tuples[Range[-1, 1], 3] instead. $\endgroup$
    – MarcoB
    Jun 16 at 15:29

1 Answer 1

4
$\begingroup$

To see why the approaches given in Syed's comment work, compare the Dimensions of the Tables

Clear["Global`*"]

Dimensions[t1 = Table[{a, b, 1}, {a, -1, 1}, {b, -1, 1}]]

(* {3, 3, 3} *)

There are three lists of three data points

ListPointPlot3D[t1, PlotLegends -> Automatic]

enter image description here

Dimensions[t2 = Table[{a, b, c}, {a, -1, 1}, {b, -1, 1}, {c, -1, 1}]]

(* {3, 3, 3, 3} *)

This dataset does not match any allowed syntax for ListPointPlot3D

ListPointPlot3D[t2]

(* ListPointPlot3D::ldata: {{{{-1,-1,-1},{-1,-1,0},{-1,-1,1}},{{-1,0,-1},{-1,0,0},{-1,0,1}},{{-1,1,-1},{-1,1,0},{-1,1,1}}},{<<1>>},{<<1>>}} is not a valid dataset or list of datasets. *)

Dimensions[
 t3 = Flatten[Table[{a, b, c}, {a, -1, 1}, {b, -1, 1}, {c, -1, 1}], 2]]

(* {27, 3} *)

This is a single list of 27 data points

ListPointPlot3D[t3, PlotLegends -> Automatic]

enter image description here

Dimensions[
 t4 = Flatten[Table[{a, b, c}, {a, -1, 1}, {b, -1, 1}, {c, -1, 1}], 1]]

(* {9, 3, 3} *)

This is nine lists of three data points

ListPointPlot3D[
 Flatten[Table[{a, b, c}, {a, -1, 1}, {b, -1, 1}, {c, -1, 1}], 1], 
 PlotLegends -> Automatic]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.