Re: Help Creating 3D List Line Plot

• To: mathgroup at smc.vnet.net
• Subject: [mg103762] Re: [mg103729] Help Creating 3D List Line Plot
• From: "David Park" <djmpark at comcast.net>
• Date: Mon, 5 Oct 2009 07:38:38 -0400 (EDT)
• References: <22507120.1254651799877.JavaMail.root@n11>

```I'm not certain if I completely understand the final plots you are trying to
make, but perhaps the following will help.

data={{0,-8,0},{0,-7,.1},{0,-6,.1},{0,-5,.2},{0,-4,.25},{0,-3,.3},{0,-2,.37}
,{0,-1,.4},{0,0,.38},{1,-7,0},{1,-6,0},{1,-5,0},{1,-4,.2},{1,-3,.2},{1,-2,.3
},{1,-1,.33},{1,0,.36},{2,-3,0},{2,-2,.1},{2,-1,.3},{2,0,.42}};

The following selects 2D data by run#.

GetDataRun[i_] := Cases[data, {i, t_, v_} -> {t, v}]

This makes a 2D line plot of all the data sets:

ListLinePlot[{GetDataRun[0], GetDataRun[1], GetDataRun[2]}]

The following selects data for a 3D Line plot.

GetDataRun3D[i_] := Cases[data, {i, t_, v_}]

This makes a 3D plot of the lines:

Graphics3D[{Line[GetDataRun3D[0]], Line[GetDataRun3D[1]],
Line[GetDataRun3D[2]]},
PlotRange -> {{-.2, 2.2}, {-8, 0}, {0, .45}},
BoxRatios -> {1/2, 1, 1},
Axes -> True,
Ticks -> {Range[0, 2], Automatic, Automatic}]

The following selects the run# and last value for each run, sorts them, and
extracts the order of the runs by ascending last value:

Table[Part[Last[GetDataRun3D[i]], {1, 3}], {i, 0, 2}]
Sort[%, Last[#1] < Last[#2] &]
First /@ %

David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/

From: Aaron Bramson [mailto:aaronbramson at gmail.com]

Hello there,

I'm trying to plot the output of my simulations as lines in a 3D Plot but I
can't coerce Mathematica do manipulate the data to make this possible.  Each
experiment is conducted for 100 runs and they each go for different
durations of time.  Getting the individual points from the output csv is
easy enough:

MyData := Import["OutputFile1.csv"]
MyPoints := Table[List[MyData[[i, 1]], MyData[[i, 20]], MyData[[i, 30]]],
{i, Length[MyData]}]

where
-1 is the column with the run number
-20 is the column with the time step
-30 is the column for measure I want to see change over time across runs

This produces something of the form:
{{0, -8, 0}, {0, -7, .1}, {0, -6, .1}, {0, -5, .2}, {0, -4, .25}, {0, -3,
.3}, {0, -2, .37}, {0, -1, .4}, {0, 0, .38}, {1, -7, 0}, {1, -6, 0}, {1, -5,
0}, {1, -4, .2}, {1, -3, .2}, {1, -2, .3}, {1, -1, .33}, {1, 0, .36}, {2,
-3, 0}, {2, -2, .1}, {2, -1, .3}, {2, 0, .42}}

But to plot the data the way I want to see them I need something like:

dat01 := {{0, -8, 0}, {0, -7, .1}, {0, -6, .1}, {0, -5, .2}, {0, -4, .25},
{0, -3, .3}, {0, -2, .37}, {0, -1, .4}, {0, 0, .38}}
dat02 := {{1, -7, 0}, {1, -6, 0}, {1, -5, 0}, {1, -4, .2}, {1, -3, .2}, {1,
-2, .3}, {1, -1, .33}, {1, 0, .36}}
dat03 := {{2, -3, 0}, {2, -2, .1}, {2, -1, .3}, {2, 0, .42}}
Show[Graphics3D[Line[Partition[dat01, Length[dat01]]]],
Graphics3D[Line[Partition[dat02, Length[dat02]]]],
Graphics3D[Line[Partition[dat03, Length[dat03]]]]]

but in an iterative fashion that goes through MyPoints and collates the
points from run# as a separate list.  (I'll worry about opacity and color
gradients later and just hope it won't be a problem.)

The data are sorted by run number and time already, but as an added bonus
I'd really like to sort the runs by the z-value of the last element of the
list..which seems not difficult once I have the individual lists by run#.

None of this would be hard in Java but indices and constructors work
differently here.  What I came up with is:
List[For[i = 1, i < 101, i++, Select[TestData, TestData[[#, 1]] = i &]]] but
that gives me an error:

"Set::pspec: Part specification #1 is neither an integer nor a list of
integers. >>"  Apparently I can't refer to an element of the sublist as an
part specification.  TakeWhile had a similar problem...I can't figure out
how to tell Mathematica to take an element if its subelement satisfies a
property.

Of course there might be a much easier way to make a 3D List Line Plot but I
haven't found anything like it anywhere.  Any help you can provide would be
greatly appreciated.

Best,
Aaron

```

• Prev by Date: Re: Re: Incorrect symbolic improper integral
• Next by Date: Re: Help Creating 3D List Line Plot
• Previous by thread: Re: Help Creating 3D List Line Plot
• Next by thread: Using Histogram with custom BinCounts function