Mathematica:Plotting an iterative list on one graph

  • Context: Mathematica 
  • Thread starter Thread starter Sarah rob
  • Start date Start date
  • Tags Tags
    Graph Iterative List
Click For Summary

Discussion Overview

The discussion revolves around plotting data from an iterative list in Mathematica, specifically focusing on how to visualize pairs of values across multiple time steps. Participants explore various methods for formatting the x-axis and y-axis, as well as how to apply color coding to specific data points.

Discussion Character

  • Technical explanation
  • Exploratory
  • Mathematical reasoning

Main Points Raised

  • One participant seeks to plot the second element of each pair from a list across multiple time steps, aiming for a specific visual arrangement.
  • Another participant suggests using a combination of Table and Transpose functions to extract the necessary data for plotting, although they cannot test the solution directly.
  • A participant inquires about reversing the y-axis direction, asking if it can be adjusted to display values from 3 to 0 instead of the standard 0 to 3.
  • Another participant responds that while the y-axis cannot be reversed directly, it can be achieved by plotting negative values and adjusting the ticks accordingly.
  • A later post asks if it is possible to color the first terms of the list differently based on their position and also requests assistance in calculating the mean of the last elements of the sublists.

Areas of Agreement / Disagreement

Participants present various methods and suggestions, but no consensus is reached on the best approach to achieve the desired plot formatting and calculations. Multiple competing views remain regarding the y-axis adjustment and color coding.

Contextual Notes

Some assumptions about the data structure and the desired output format are not explicitly stated, which may affect the proposed solutions. The discussion also lacks resolution on the effectiveness of the suggested methods for achieving the participant's goals.

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 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
943