Mathematica:Plotting an iterative list on one graph

In summary, you cannot change the y-axis to run from bottom to top. You can plot y instead and use ticks in your options.}
  • #1
Sarah rob
16
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

  • sample graph1.xls
    27 KB · Views: 205
Physics news on Phys.org
  • #2
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).
 
  • #3
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
 
  • #4
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.
 
  • #5
{ {{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:

1. What is Mathematica?

Mathematica is a computational software program used for mathematical and scientific computations, data analysis, and visualization. It is widely used by scientists, engineers, and mathematicians for various purposes.

2. How do I plot an iterative list on one graph in Mathematica?

To plot an iterative list on one graph in Mathematica, you can use the ListPlot function. First, create a list of the values you want to plot, and then use the ListPlot function to plot them on a graph. You can also add options to customize the appearance of the graph, such as adding labels, changing the color and style of the plot, and adding a legend.

3. Can I plot multiple iterative lists on one graph in Mathematica?

Yes, you can plot multiple iterative lists on one graph in Mathematica. To do so, you can use the ListPlot function with a list of lists as input. Each list in the input list will be plotted on the same graph, and you can customize the appearance of each plot using different options.

4. How can I add a title and axis labels to my plot in Mathematica?

To add a title and axis labels to your plot in Mathematica, you can use the PlotLabel and AxesLabel options in the ListPlot function. The PlotLabel option allows you to add a title to your plot, while the AxesLabel option allows you to add labels to the x and y axes.

5. Is it possible to save my plot as an image file in Mathematica?

Yes, you can save your plot as an image file in Mathematica. To do so, you can use the Export function and specify the file format you want to save your plot as, such as PNG, JPEG, or PDF. You can also specify the size and resolution of the image in the Export function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
147
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
697
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
741
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • Linear and Abstract Algebra
Replies
4
Views
870
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • Precalculus Mathematics Homework Help
Replies
21
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top