Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Help Creating 3D List Line Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103755] Re: [mg103729] Help Creating 3D List Line Plot
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Mon, 5 Oct 2009 07:37:19 -0400 (EDT)
  • References: <200910040935.FAA07754@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

First of all, defining MyData as you have, with SetDelayed, will cause the  
input file to be read all over again EVERY time MyData is used. Use Set,  
and you'll read it only once.

myData = Import["OutputFile1.csv"];

Secondly, defining MyPoints with SetDelayed will cause the Table to be  
evaluated all over again EVERY time MyPoints is used, and that will  
involve a LOT of mentions of MyData, so you'll read the file many, MANY  
times.

Third, I recommend you NEVER capitalize your own user variables. If you  
follow that practice, it will always be obvious whether a symbol is yours  
or a built-in Mathematica symbol, and you'll avoid accidentally shadowing  
a Mathematica function that you might need.

Fourth, we can split the data using Split and sort each run using SortBy  
and Map:

myData = {{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}};
unsortedRuns = Split[myData, First@#1 == First@#2 &];
runs = SortBy[#, Last] & /@ unsortedRuns

{{{0, -8, 0}, {0, -7, 0.1}, {0, -6, 0.1}, {0, -5, 0.2}, {0, -4,
    0.25}, {0, -3, 0.3}, {0, -2, 0.37}, {0, 0, 0.38}, {0, -1,
    0.4}}, {{1, -7, 0}, {1, -6, 0}, {1, -5, 0}, {1, -4, 0.2}, {1, -3,
    0.2}, {1, -2, 0.3}, {1, -1, 0.33}, {1, 0, 0.36}}, {{2, -3,
    0}, {2, -2, 0.1}, {2, -1, 0.3}, {2, 0, 0.42}}}

Here are some simple 3D plots:

Graphics3D[{Line /@ runs, Point /@ myData}]

ListPointPlot3D[runs]

You can work with various options of Graphics3D or ListPointPlot3D to  
rotate or frame the graphic, label the axes, color the lines, vary the  
point sizes, or whatever.

Here are three 2D plots:

ListPlot[#, Joined -> True] & /@ runs[[All, All, 2 ;; 3]]

and here's a single 2D plot:

Show[ListPlot[#, Joined -> True] & /@ runs[[All, All, 2 ;; 3]]]

Bobby

On Sun, 04 Oct 2009 04:35:05 -0500, Aaron Bramson <aaronbramson at gmail.com>  
wrote:

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


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Help Creating 3D List Line Plot
  • Next by Date: Re: Re: Making raw HTML appear in a notebook exported to
  • Previous by thread: Help Creating 3D List Line Plot
  • Next by thread: Re: Help Creating 3D List Line Plot