Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have an external program which generates a set of data - X points at the time t1, X points at the time t2 and so on. These points are stored in CSV file and I can change the format if necessary.
What is the easiest way to plot and manipulate them, so I can click "play" and see the dynamics of process?

UPD:
For example, points at t1:

0.2 42.8
0.4 12.3
0.6 32.1
0.8 37.3

Points at t2:

0.2 44.2
0.4 17.8
0.6 39.0
0.8 30.1

It is always a constant number of points at any time (4 in example). I can export them to separate CSV files or in the one file and change format in any way necessary, like adding a new column.

share|improve this question
    
Welcome, Andrew. Please consider posting a small sample of your data, or a representative approximation. Also, what kind of plot do you desire? –  Mr.Wizard Jun 9 '12 at 9:00
    
@Mr.Wizard Thanks, I have updated the question. Line plot. –  Andrew Jun 9 '12 at 9:13
    
You could, you know, do something like Map[ListPlot, {t1Points, t2Points, ...}] and then use ListAnimate[] on those... –  J. M. Jun 9 '12 at 9:17
    
@J.M. you mean what I did below? :^) –  Mr.Wizard Jun 9 '12 at 9:17
    
@Mr. Wizard: slow typist... :D –  J. M. Jun 9 '12 at 9:20
show 1 more comment

2 Answers

up vote 8 down vote accepted

Load your data with Import["data.csv"] and process as necessary into:

data = {
  {{0.2`, 42.8`}, {0.4`, 12.3`}, {0.6`, 32.1`}, {0.8`, 37.3`}},
  {{0.2`, 44.2`}, {0.4`, 17.8`}, {0.6`, 39.`},  {0.8`, 30.1`}}
  };

Build a sequence of plots with a fixed PlotRange to stabilize the image, and ListAnimate:

ListAnimate[
   ListLinePlot[#, PlotRange -> {10, 50}] & /@ data
]

Mathematica graphics

share|improve this answer
    
Thanks, this is exactly what I needed. –  Andrew Jun 9 '12 at 9:23
2  
@Andrew you're welcome. Please make your future questions as specific as possible, and include sample data and executable code when appropriate. –  Mr.Wizard Jun 9 '12 at 9:26
add comment

Then add some salt

q = 20;
pos = Table[.1 i, {i, q}];
{start, end} = RandomReal[1, {2, q}];
pts[i_Integer, t_Real] := {pos[[i]], (1 - t) start[[i]] + t end[[i]]}
c[t_Real] := Interpolation[Table[pts[i, t], {i, q}], Method -> "Spline"];

Manipulate[
  Plot[c[t][x], {x, 0.1, 2},
   PlotRange -> {{0, 2.1}, {-.5, 1.2}},
   Epilog -> {
     Red,   PointSize[0.01], Point@Table[pts[i, t], {i, q}],
     Green, Line@Partition[Riffle[Transpose[{pos, start}], Transpose[{pos, end}]], 2]
     }],
  {t, 0.01, .99, .05}]

enter image description here

Edit

Found some code I used in a project eons ago. You could do very weird things with your points' trajectories if you take some precautions:

(*Let's create a points file sample *)
s = Transpose@Table[{i + Cos[2 Pi k/10], Sin[2 Pi i/10] + Sin[2 Pi (k + 3)/10]}, 
                   {i, 0, 10, 1.}, {k, 0, 10, 1.}];
Export["c:\\table.csv", Flatten[s, 1]];
ClearAll[s];

    (*Main fun def*)
maniPointPlot[pts_, n_] := Module[{sets, steps, curve, pp, enlarge, bounds, apt},

   sets = MapIndexed[{#2[[1]], #1} &, Partition[pts, n], {2}];(*Add time indicator*)
   bounds = {Min@#, Max@#} & /@ Transpose@pts;(*Bounds for Plot*)
   steps = Length@sets;(*Time span*)

   (*Memoize Positions of point # over time " / All Points Together*)
   apt[t_] := apt[t] = Interpolation[#, Method -> "Spline"][t] & /@ Transpose@sets;
   (*Curve at time t*)
   curve[t_] := Interpolation[apt@t, Method -> "Spline"];

   (*aux func for interval dilation*)
   enlarge[{a_, b_}] := {a - #, b + #} &@(Abs[b - a]/10);
   (*Green Points traces*)
   pp = ParametricPlot[apt@t, {t, 1, steps}, ColorFunction -> (Green &)];

   (*Our little beast follows*)
   Manipulate[
    Show@{Plot[curve[t][x], Evaluate@{x, Sequence@@bounds[[1]]}, PlotRange -> enlarge /@ bounds],
          Graphics[Point@apt@t],
          pp}, {t, 1, steps}]];

(*Now your code*)

s = Import["c:\\table.csv"]; (*Read the table*)
nbr = 11; (*number of points in each set*)
Off[InterpolatingFunction::dmval];
maniPointPlot[s, nbr]

enter image description here

Cozy crawling cardioids:

enter image description here

share|improve this answer
2  
And don't forget the bacon... because everything is better with bacon. –  jmlopez Jun 9 '12 at 22:18
    
@jmlopez I was going to said something about the beer. Byt i"n two drjnk tp rimemver wat uas itjs/ –  belisarius Jun 9 '12 at 22:29
1  
Que? lol, I should go grab one too... –  jmlopez Jun 9 '12 at 22:31
3  
Okay that's pretty slick. +1 –  Mr.Wizard Jun 11 '12 at 1:50
    
Are you a wizard? –  Andrew Jun 11 '12 at 18:58
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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