Plotting Nested Lists in Mathematica

  • Mathematica
  • Thread starter ChristinaJ
  • Start date
  • #1
ChristinaJ
Gold Member
43
1
All,

I am having trouble plotting nested lists.

I have two data sets (A and B), both with dimensions 5x50.

So far I have

plot = Map[
ListPlot[#, PlotRange -> {0, Max[A]},
AxesOrigin -> {0, 0}, Frame -> True,
FrameLabel -> {"position", "Intensity"}] &, A];

which gives me 5 plots of 50 points each. What I need is to also plot data B together with data A, ending with 5 plots each having two lines of 50 points.

Each plot is ListPlot[An,Bn] where n=1..5 but I just can't figure it out.

Many thanks for any help and apologies for trespassing upon your time.

Christina
 

Answers and Replies

  • #2
313
1
I think that you just need to transpose your data:

Code:
A = Accumulate /@ RandomReal[{0, 2}, {5, 50}];
B = Accumulate /@ RandomReal[{0, 1}, {5, 50}];

ListPlot[#, PlotRange -> {0, Max[A]}, AxesOrigin -> {0, 0}, 
   Frame -> True, Joined -> True, 
   FrameLabel -> {"position", "Intensity"}] & /@ Transpose[{A, B}]

attachment.php?attachmentid=34374&stc=1&d=1302822454.png


You can also get the same results using Table and Part ( [[ ]] )

Code:
Table[ListPlot[{A[[i]], B[[i]]}, PlotRange -> {0, Max[A]}, 
  AxesOrigin -> {0, 0}, Frame -> True, Joined -> True, 
  FrameLabel -> {"position", "Intensity"}], {i, 1, 5}]
 

Attachments

  • Untitled-2.png
    Untitled-2.png
    9.5 KB · Views: 698
  • #3
ChristinaJ
Gold Member
43
1
It worked perfectly, just what I was looking for.

Many thanks for your help.

Christina
 

Related Threads on Plotting Nested Lists in Mathematica

Replies
1
Views
3K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
2
Views
8K
  • Last Post
Replies
3
Views
14K
  • Last Post
Replies
9
Views
15K
Replies
3
Views
809
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
6
Views
13K
  • Last Post
Replies
1
Views
2K
Top