0
$\begingroup$

I have a text file which is the following format:

1159, 2209, 19, 141
2169, 1827, 23, 54

Which I import, sort and gather using:

table = Import["/Users/myname/Documents/tablevalues.txt", 
  "Table", "FieldSeparators" -> ","];
table = Sort[table, #1[[4]] < #2[[4]] &];
a=GatherBy[table, Last];

What I would like to do is make a 3D point plot using the first 3 values in every line, an only show the points that have the same 4 value at one time.

So basically, this:

ListPointPlot3D[GatherBy[table, Last][[i]][[All, 1 ;; 3]]]

where i would be the fourth value in each line, but animated so that I can change the value of i with a slider.

$\endgroup$
1
$\begingroup$

You seem to know all the pieces you need except for Manipulate. As a self-contained example:

table = RandomInteger[10, {100, 4}];
a = GatherBy[table, Last];

Manipulate[
 ListPointPlot3D[ a[[i]][[All, 1 ;; 3]] ],
 {i, 1, Length @ a, 1}
]

An additional example this time using GroupBy, and a few customizations.

table[[All, 4]] *= 7;  (* change values in fourth column for illustration only *)

a = GroupBy[table, Last -> Most];

Manipulate[
 ListPointPlot3D[a[i], 
   PlotLabel -> Row[{"fourth column value is ", i}]],
 {i, Sort @ Keys @ a, ControlType -> Slider}
]

One more example regarding your need for multiple data sets in one plot.

t1 = RandomInteger[10, {100, 4}];
t2 = RandomInteger[{-5, 5}, {100, 4}];

{a, b} = GroupBy[#, Last -> Most] & /@ {t1, t2};

Manipulate[
  ListPointPlot3D[{a[i], b[j]},
    PlotStyle -> PointSize[Large],
    PlotRange -> {{-5, 10}, {-5, 10}, {-5, 10}},
    PlotLabel -> Grid[{{"t1 set 4th col val: ", i},
                       {"t2 set 4th col val: ", j}}]
  ],
  {i, Sort @ Keys @ a, ControlType -> Slider},
  {j, Sort @ Keys @ b, ControlType -> Slider}
]

Note that I used an explicit PlotRange to keep the points from visually jumping around.

$\endgroup$
  • $\begingroup$ Would it be possible to make the slider use values from the 4th column of the text file? $\endgroup$ – yellowdiamond Jul 8 '16 at 2:01
  • $\begingroup$ @yellowdiamond Yes. For best result which version of Mathematica are you using? $\endgroup$ – Mr.Wizard Jul 8 '16 at 2:01
  • $\begingroup$ I am using version 10.4.0.0 $\endgroup$ – yellowdiamond Jul 8 '16 at 2:02
  • $\begingroup$ @yellowdiamond Please see my additional example. $\endgroup$ – Mr.Wizard Jul 8 '16 at 2:09
  • $\begingroup$ I ran the new code, but the "fourth column .." number is reading in the 10s of thousands rather than highest possible value (from where the data was generated from) of 2500 $\endgroup$ – yellowdiamond Jul 8 '16 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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