Issue with ListPlot3D Mathematica

  • Mathematica
  • Thread starter Maior272
  • Start date
  • Tags
    Mathematica
In summary: So you end up with a list of all the coordinates, and ListPlot3D can plot them.In summary, The conversation discusses the process of writing a script to evaluate and plot a series of 100 spectra. The spectra data is provided in separate files and needs to be normalized using a whitelightspectrum. The process involves using two for loops to calculate the normalized values and storing them in a table. However, the final step of plotting the data using ListPlot3D only returns an empty box. The expert suggests using the Flatten function to flatten the list of lists of coordinates to a single list, allowing ListPlot3D to plot the data successfully.
  • #1
Maior272
1
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
  • #2
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.
 

1. What is ListPlot3D in Mathematica and how is it used?

ListPlot3D in Mathematica is a function that creates a 3D scatter plot from a list of data points. It is used to visualize data in three dimensions and can be used to identify patterns or trends in the data.

2. How do I customize the appearance of my ListPlot3D graph?

ListPlot3D offers various options for customizing the appearance of the graph, such as changing the color, size, and shape of the data points. These options can be specified in the function's parameters or by using the Graphics3D options.

3. Can I add labels or annotations to my ListPlot3D graph?

Yes, you can add labels and annotations to your ListPlot3D graph by using the Epilog or Prolog options. These allow you to add text, shapes, or other graphics to your graph.

4. How can I plot multiple datasets on the same ListPlot3D graph?

To plot multiple datasets on the same ListPlot3D graph, you can use the Show function to combine individual plots. Alternatively, you can use the ListPlot3D option PlotStyle to specify different styles for each dataset.

5. What should I do if my ListPlot3D graph is not displaying my data correctly?

If your ListPlot3D graph is not displaying your data correctly, check that your data is in the correct format and that you have specified the correct options for your graph. You can also try adjusting the range of the axes or using the ScalingFunctions option to improve the visualization of your data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
262
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top