Plotting Nested Lists in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter ChristinaJ
  • Start date Start date
  • Tags Tags
    Mathematica Plotting
Click For Summary
SUMMARY

This discussion focuses on plotting nested lists in Mathematica, specifically combining two datasets (A and B) of dimensions 5x50 into a single plot for each dataset. The user initially attempted to plot the datasets separately using ListPlot but required a solution to plot them together. The solution involves using the Transpose function to combine the datasets and employing ListPlot with the Joined option to create the desired visual output. The final code snippets provided successfully achieve the goal of displaying both datasets in a single plot for each of the five plots.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of ListPlot function in Mathematica
  • Knowledge of data structures, specifically nested lists
  • Experience with functions like Transpose and Accumulate in Mathematica
NEXT STEPS
  • Explore advanced plotting techniques in Mathematica, such as using Plotly for interactive visualizations
  • Learn about data manipulation functions in Mathematica, including Map and Table
  • Investigate the use of Joined option in ListPlot for connecting data points
  • Study the Accumulate function for cumulative data visualization in Mathematica
USEFUL FOR

This discussion is beneficial for data analysts, mathematicians, and researchers using Mathematica who need to visualize multiple datasets in a single plot effectively.

ChristinaJ
Gold Member
Messages
34
Reaction score
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
 
Physics news on Phys.org
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
    8.7 KB · Views: 931
It worked perfectly, just what I was looking for.

Many thanks for your help.

Christina
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 18 ·
Replies
18
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K