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'm trying to create a simulation of a set of lists with Manipulate[] and ListLinePlot[]. However, as my simulation starts with the $x$-axis pre-defined (DataRange -> {1, 500}), the lists behave strangely, i.e., they are not plotted as intended. The lists do not obbey the $x$-axis (which is correctly plotted), but instead of that they are always at the right edge of the plot.

My code is:

randomWalk[x_]:=Accumulate[Prepend[RandomVariate[NormalDistribution[0, 1], x], 0]]
exchange=Table[Subscript[asset, i] = randomWalk[500], {i, 1, 5}];
Manipulate[ListLinePlot[exchange[[All, 1 ;; n]], DataRange -> {1, 500}], {n, 3,500, 1}]

Could someone give me a hint to solve this problem?

share|improve this question
2  
Perhaps you mean to use PlotRange instead. Try replacing your DataRange->{1,500} with PlotRange -> {{1, 500}, {-40, 40}}. –  Andy Ross Apr 9 '13 at 0:29
    
Yay! This works perfectly! Thanks! –  Rod Apr 9 '13 at 0:30
add comment

1 Answer

up vote 3 down vote accepted

What you want here is PlotRange. The following does what you intend.

randomWalk[x_] := Accumulate[Prepend[RandomVariate[NormalDistribution[0, 1], x], 0]]
exchange = Table[Subscript[asset, i] = randomWalk[500], {i, 1, 5}];
Manipulate[ListLinePlot[exchange[[All, 1 ;; n]], 
  PlotRange -> {{1, 500}, {-40, 40}}]
, {n, 3, 500, 1}]

enter image description here

share|improve this answer
    
The only thing I would change now is to put the $y$-axis at the left side of the plot and use PlotRange -> {{1, 500}, {Min[exchange], Max[exchange]}}. Anyway, thanks a lot !! –  Rod Apr 9 '13 at 0:36
1  
To put the y-axis on the left you can fix it with AxesOrigin->{1,0}. –  Andy Ross Apr 9 '13 at 0:39
    
I've done that too! Thanks again! –  Rod Apr 9 '13 at 0:42
add 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.