2
$\begingroup$

I have a transient absorption spectrum(TAS) saved as a 240x3648 matrix, I want to use ListDensityPlot to plot it, but something is wrong:

delay = Table[i*5.2`5 - 120*5`5, {i, 1, 240}];
frequency = Flatten[Import["frequency.csv"]];
spec = Import["spectrum.dat", "Data"];
spec1 = 
  Flatten[
    Table[{delay[[j]], frequency[[k]], spec[[j, k]]}, {j,1,240}, {k, 1, 3648}], 
    1];
ListDensityPlot[spec1, AxesLabel -> {"Delay", "Frequency"}]

The right side is totally wrong, but when I change the fourth line of the code to

spec1 = Flatten[Table[{j, k, spec[[j, k]]}, {j,1,240}, {k, 1, 3648}], 1];

then the result will be all right.

This is not what I want. Please help me!

I can't put on more than two links, but the frequency can be replaced by any 3648 array. The OneDrive link of the spectrum file: https://1drv.ms/u/s!Ahthsev5X2HBhKF-fWIK7Zl6qvwjtQ , and frequency file:https://1drv.ms/u/s!Ahthsev5X2HBhKE46K7C5eFTqtKNXA

$\endgroup$
  • 3
    $\begingroup$ Mathematica always makes better plots of 3D data when the data is given as an array of $z$-values, versus when you give the data as a list of $\{x, y, z\}$ tuples. I believe in this case, you are experiencing this bug. Try something like ListDensityPlot[Transpose@spec, AspectRatio -> 1/2, DataRange -> {{-594.8, 648}, {1.55, 1.60}}, FrameLabel -> {"Delay", "Frequency"}, PlotLegends -> Automatic] instead $\endgroup$ – Jason B. Jun 15 '17 at 20:55
  • $\begingroup$ @Jason In the way you give out, the plot is working normally. But there is a problem: the vertical coordinates is not well-proportioned! The Y-coordinate space between different data points could be different. It is caused by the operating mode of the spectrometer and can not be changed. So... $\endgroup$ – Bettertomo Jun 16 '17 at 1:42
  • $\begingroup$ @Jason May be I have to change the ticks by option "Ticks->{}", a laborious way. $\endgroup$ – Bettertomo Jun 16 '17 at 1:47
  • $\begingroup$ actually I had to guess about the y axis range because the frequency csv file wasn't posted. If your frequency data is just a linear array of regularly spaced points, then just give the min and max values to DataRange and the tickmarks should line up thte same $\endgroup$ – Jason B. Jun 16 '17 at 14:26
  • $\begingroup$ My reputation is too little so I can't post more than two links. I have delete the link for result of the plot and add the frequency file. I'm a China student, so maybe I'm in sleep but you're in daylight, sorry to respond slowly. $\endgroup$ – Bettertomo Jun 18 '17 at 10:07
2
$\begingroup$

This is another manifestation of this bug:

The solution for that issue is not to keep your data in the form of {x, y, z} tuples, but keep it as a rectangular array. Then you can just feed the x and y ranges for the tick marks to the DataRange option.

ListDensityPlot[Transpose@spec, AspectRatio -> 1/2, 
 DataRange -> {MinMax@delay, MinMax@frequency}, 
 FrameLabel -> {"Delay", "Frequency"}, PlotLegends -> Automatic]

enter image description here

You can get just as good a plot, in much less time, if you resample the data to have fewer points.

resampledData = ArrayResample[ Transpose @ spec, {500, 240}];
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks. At first I want to plot with totally accurate original data from the experiment, now I think I have to use a more economical way. $\endgroup$ – Bettertomo Jun 19 '17 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.