I have a problem visualizing my dataset.

I have 2000 files that are composed of time t and intensity Int coordinates (.dat extension). For all data files the time coordinates are the same. When I load the data set:

FileNames["*"] // (# // Import[#, "Table"] &) & /@ # &

I can easily visualize it as ListPlot (all curves in one plot), but it is a bit overloaded with data.

I thought that ListDensityPlot could be a nice option with x axis as time, y axis as number of the file (from 1-2000) and f (color) as my intensity value, but it fails. When loaded, my dataset has dimensions 2000,600,2 , which is a problem that I cannot solve.

Any suggestions?

  • $\begingroup$ Are there only two intensities? $\endgroup$ – Feyre Jan 5 '17 at 13:27
  • $\begingroup$ no, dimensions of dataset is 2000,600,2 - Hence, I have 600 intensities per file $\endgroup$ – ratt4 Jan 5 '17 at 14:30
  • $\begingroup$ So if 2000=files, 600=intensities, then what's the third dimension of length 2? $\endgroup$ – Feyre Jan 5 '17 at 14:32
  • $\begingroup$ two columns. and that is the problem, because instead of having a array with n=2000, time=600 and int=600 I have an 3D array with n=2000, length=600 and depth of 2 $\endgroup$ – ratt4 Jan 5 '17 at 14:56
  • $\begingroup$ I don't see how anyone can help without access to at least one of the data files. $\endgroup$ – Feyre Jan 5 '17 at 15:05

(1) Get the file names and import the data:

fn = FileNames[];
dat = Import /@ fn;

(2) Extract the "x"-values from one of the file names, the "y"-values from one of the data sets (say, the first), and the "z"-values from all the data sets:

xs = ToExpression@StringReplace[fn, {"x_" -> "", ".dat" -> ""}];
ys = dat[[1, All, 1]];
zs = dat[[All, All, 2]];

(3) Create a list of triplets (this can be also done more elegantly, but I did it like this so it would be readable):

dat2 = Flatten[
       Table[{xs[[i]], ys[[j]], zs[[i, j]]}, {i, Length@xs}, {j, Length@ys}]
       , 1];

(4) Plot:

  • $\begingroup$ Woah, it works! thanks a lot! $\endgroup$ – ratt4 Jan 5 '17 at 17:46
  • $\begingroup$ @ratt4 You're welcome, and welcome to mathematica.SE. Please consider accepting the answer if you're satisfied with the solution so that other users will know that it's solved and does not require more attention. $\endgroup$ – yohbs Jan 5 '17 at 17:49

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.