PDA

View Full Version : Mathematica:Plotting an iterative list on one graph


Sarah rob
Jan11-11, 07:05 PM
Hi
i want the x -axis to go from 1 to 5, then plot the 2nd element of each pair, (so that they appear in a horizontal row ) for
lis = {{4, 2}, {1, 3}, {2, 5}}

I' ve been playing around with ListPlot and using it with Map[Last,
lis] but not getting what i want

my goal is to repeat this for all 3 time steps
flist = {{{4, 2}, {1, 3}, {2, 5}},
{{1, 2}, {3, 4}, {3, 1}},
{{2, 3}, {0, 5}, {2, 2}}}
so that they appear on seperate rows like the grap shown in the
attachment that i created in excel

Note : im guessing it would be easier to solve if i didn' t have
pairs in the list but the NestList i have created to get these lists \
need to be in this form

CompuChip
Jan12-11, 02:32 AM
I do not have Mathematica here so I cannot test it, but you could try something like

Table[{i, #}& /@ (Last[Transpose[flist[[i]]]]), {i, 1, Length[flist]}]


I.e. looking at flist[[1]] == {{4, 2}, {1, 3}, {2, 5}}, you transpose to get {{4, 1, 2}, {2, 3, 5}} of which Last[...] gives {2, 3, 5}. Then you map that to a function that takes each of these elements n and produces a list {1, n}, so in the end you will get something like
{{1, 2}, {1, 3}, {1, 5}}.
If you Table that over all other indices, you will get something like
{ {{1, 2}, {1, 3}, {1, 5}}, {{2, 2}, {2, 4}, {2, 1}}, {{3, 3}, {3, 5}, {3, 2}} }
which ListPlot should be able to handle (perhaps after Flatten[..., 1]ing or Partition[Flatten[...], 2]ing it).

Sarah rob
Jan13-11, 08:44 AM
Thank you CompuChip

Can I change the y-axis so that it goes (bottom to top) from say 3 to 0 rather that the usual 0 to 3

CompuChip
Jan13-11, 09:11 AM
You cannot make it run the other way. What you can do is plot -y instead, and use ticks in your options:

ListPlot[..., AxesOrigin->{0, -3}, Ticks[Automatic, {Range[{-y, y}, {y, 0, 3}]}]

which will put the origin of your axes at y = -3 and place the labels "0", "1", "2" and "3" at y = 0, -1, -2 and -3 respectively.

Sarah rob
Jan15-11, 05:48 PM
{ {{1, 2}, {1, 3}, {1, 5}},
{{2, 2}, {2, 4}, {2, 1}},
{{3, 3}, {3, 5}, {3, 2}} }
Is it possibe to colour all the 1st terms of the list e.g. {1,2}, {2,2}, {3,3} blue, {1,3},
{2,4},{3,5} green and {1,5}, {2,1}, {3,2} red using PlotMarker or a simular function

Also, can i find the mean of the last elements of the sublist,
ie. the mean of 2, 3, 5, the mean of 2, 4, 1 and the mean of 3, 5, 2
my attempts haven't been very successful :(