Mathematica Mathematica:Plotting an iterative list on one graph

AI Thread Summary
The discussion focuses on plotting data from a list of pairs in Mathematica, specifically using ListPlot to visualize elements across multiple time steps. The user seeks to plot the second element of each pair horizontally for three different time steps, represented in a nested list format. Suggestions include using Table and Transpose functions to extract and format the data correctly for plotting. Additionally, the user inquires about reversing the y-axis, which can be achieved by plotting negative values and adjusting ticks accordingly. There is also a request to color specific terms in the plot using PlotMarker or similar functions. Finally, the user seeks assistance in calculating the mean of the last elements from each sublist, indicating challenges in their attempts to achieve this. Overall, the discussion emphasizes data manipulation and visualization techniques in Mathematica.
Sarah rob
Messages
16
Reaction score
0
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 separate rows like the grap shown in the
attachment that i created in excel

Note : I am 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
 

Attachments

Physics news on Phys.org
I do not have Mathematica here so I cannot test it, but you could try something like
Code:
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).
 
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
 
You cannot make it run the other way. What you can do is plot -y instead, and use ticks in your options:
Code:
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.
 
{ {{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 :(
 
Last edited:

Similar threads

Replies
3
Views
2K
Replies
2
Views
2K
Replies
1
Views
3K
Replies
5
Views
2K
Replies
2
Views
2K
Replies
6
Views
4K
Replies
22
Views
3K
Replies
2
Views
3K
Replies
2
Views
272
Back
Top