1
$\begingroup$

I'm writing a processor in Mathematica to get some analytics on some data I've collected via a hadoop MapReduce process.

It's a list of records in the form

<float>, tc:<int>, m:<int>, h:<int>; <float>

I do some messy processing and extract a list of tuples in the form {<int>, <int>, <float>} (which corresponds to x, y, z) which I want to plot using ListPlot3D.

data = (* <processed data in form of list of {<c:<int>,m:<int>,h:<int>,<float>}> *)

plotPoints = 
 Table[
   {N[Part[StringSplit[Part[x, 1], ":"], 2]], 
    N[Part[StringSplit[Part[x, 1], ":"], 2]], 
    N[Part[x, 4]]}, 
  {x, data}]
ListPointPlot3D[plotPoints, PlotRange -> All, DataRange -> All]

In my output, the list plotPoints looks correct, but plotting it creates an empty plot, and using ListPointPlot3D gives the error

Last {} has zero length and no last element.

This is what the output from plotPoints and ListPlot3D looks like

The error I'm seeing

Edit

For better debugging here is the full script:

data = 
    Join[
      Part[
        Part[
          Select[#, compare], 1] & /@ 
            StringSplit[Take[StringSplit[#, ";"], 1], "\t"], 
          1] & /@ #, 
      Take[Part[StringSplit[#, ";"], 3], {2}]] & 
  /@ 
    Import["nh-r-00000"]

plotPoints = 
  Table[
    {N[Part[StringSplit[Part[x, 1], ":"], 2]], 
     N[Part[StringSplit[Part[x, 1], ":"], 2]], 
     N[Part[x, 4]]}, 
   {x, data}]

ListPlot3D[plotPoints, PlotRange -> All]

Dataset: http://sta.sh/02dfd34p35pp

$\endgroup$
3
  • $\begingroup$ Well come to mathematica.stackexchange.com!!!!! To make it easier to get your question answered try to clarify what's "x". Also, try to generate a small dummy matrix with Ramdon[], so that we can see all of your code. $\endgroup$
    – ivbc
    Commented May 26, 2017 at 16:29
  • 1
    $\begingroup$ Would you mind uploading (a small subset of) your "data I've collected via a hadoop MapReduce process" somewhere, so it can be tested out? $\endgroup$ Commented May 26, 2017 at 16:30
  • $\begingroup$ @J.M. I added a sta.sh link to the full dataset that I'm using for testing (as well as how i am splitting it, the splitting is a bit nasty so I wouldn't be surprised if im doing something egregious there) $\endgroup$ Commented May 26, 2017 at 16:36

1 Answer 1

3
$\begingroup$

There must be a problem with your data set since random data works fine. Can't say what the problem is since you did not provide a representative sample that exhibits the problem.

plotPoints = {
    RandomInteger[{2000, 20000}, 100],
    RandomInteger[{2000, 20000}, 100],
    RandomReal[{10^5, 10^6}, 100]} // Transpose;

Verifying the form of the data

plotPoints[[1 ;; 3]]

(*  {{5603, 12887, 902134.}, {2059, 3254, 103759.}, {14340, 19104, 768750.}}  *)

Plotting the data

ListPointPlot3D[plotPoints, PlotRange -> All]

enter image description here

You probably don't want to use the option DataRange->All

ListPointPlot3D[plotPoints, PlotRange -> All, DataRange -> All]

enter image description here

EDIT: Using your data

data = Flatten[
   Rest /@ Import["/Users/roberthanlon/Documents/_Mma Temp 2/data.txt", 
     "Table"]];

Examining form

data[[1 ;; 3]] // FullForm

enter image description here

data2 = ToExpression[
   StringSplit[
      StringReplace[#, {"c:" :> "", "m:" :> "", "h:" :> "", ";" :> ","}], 
      ","] & /@ data];

Examining form

data2[[1 ;; 3]] // FullForm

enter image description here

plotPoints = data2[[All, {1, 2, 4}]];

ListPointPlot3D[plotPoints, PlotRange -> All]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ if this was a western you would be way too fast on the trigger sir!!!! $\endgroup$
    – ivbc
    Commented May 26, 2017 at 16:32
  • $\begingroup$ Yeah, thanks for the validation. It's pretty clear (especially after looking at Mathematica docs) that something in the way to data is being stored isn't quite right. Though it's a bit unclear because it looks ok in the output (like if i copy paste from output and store it is as a variable directly it works) $\endgroup$ Commented May 26, 2017 at 16:39
  • $\begingroup$ Yeah, this got it. I looked at my code and when I replace N with ToExpression, it started working. Now I feel pretty silly about this issue. $\endgroup$ Commented May 26, 2017 at 17:23

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.