Issue with ListPlot3D Mathematica

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

The discussion centers on an issue with using ListPlot3D in Mathematica to visualize spectral data. The user attempts to plot data derived from 100 spectral files, but encounters an empty plot despite correct dimensions. The solution provided involves using the Flatten function to convert the nested list structure of the data into a format compatible with ListPlot3D. Specifically, the command ListPlot3D[Flatten[data, 1]] is recommended to resolve the plotting issue.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of spectral data processing
  • Knowledge of data structures in Mathematica, particularly lists
  • Experience with plotting functions in Mathematica, specifically ListPlot3D
NEXT STEPS
  • Explore the use of Flatten in Mathematica for data manipulation
  • Learn about data visualization techniques in Mathematica
  • Investigate advanced plotting options in ListPlot3D
  • Study best practices for handling and processing large datasets in Mathematica
USEFUL FOR

This discussion is beneficial for Mathematica users, data scientists, and researchers working with spectral data who need to visualize complex datasets effectively.

Maior272
Messages
1
Reaction score
0
Hi everybody,

I am relatively new to Mathematica, so please don't be to harsh on me regarding beginners' mistakes ;-)

I wanted to write a script, which evaluates and plots a series of 100 spectra. Therefore I have 100 spectral data files, which provide the spectrum in the first 1340 lines and background in the second 1340 lines. Additionaly I want to normalize the spectrum with a whitelightspectrum recorded in a second file.
Hence I want to calculate (Spectrum-Background)/whitelight for each value.
Therefore I calculate all the values using 2 interlaces for loops putting the values in a table, which works fine.
My problem appears in the very last step as I want to plot the data using ListPlot3D which only returns an empty box (however it has the right dimensions).

I would appreciate very much you help :-)

Here is my source code:

ClearAll["Global`*"]
numspectra = 100;
time = 0;
data = Table[datafunc, {i1, numspectra}, {i2, 1340}, {i3, 3}];
spectrum = Table[Import["...\#1_13_" <> ToString <> ".txt", "Data"], {i, numspectra}];
whitelight = Table[Import["...\white 100spec_53_" <> ToString <> ".txt", "Data"], {u, numspectra}];
ToExpression[spectrum]
ToExpression[whitelight]

For[h = 1, h <= numspectra, h++,
time = time + 1;
For[j = 1, j <= 1340, j++,
wavelength = Part[spectrum, h, j, 1];
If[Part[whitelight, h, j, 3] == 0, Part[whitelight, h, j, 3] = 1, Null]; (*Avoid division by 0*)
bgcorr = (Part[spectrum, h, j, 3] - Part[spectrum, h, 1340 + j, 3])/ Part[whitelight, h, j, 3];

Part[data, h, j, 1] = wavelength;
Part[data, h, j, 2] = time;
Part[data, h, j, 3] = bgcorr;
]
]
ListPlot3D[data]
 
Physics news on Phys.org
I think that what you need is:

ListPlot3D[Flatten[data,1]]

The problem is that data is a list of lists of coordinates (each coordinate being a list of 3 coordinates, in your case wavelength, time, and bgcorr). ListPlot3D expects a list of coordinates, not a list of lists of coordinates. Flatten flattens out the top level of the list.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 52 ·
2
Replies
52
Views
13K