# ListDensity plot from many lists

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?

• Are there only two intensities? – Feyre Jan 5 '17 at 13:27
• no, dimensions of dataset is 2000,600,2 - Hence, I have 600 intensities per file – ratt4 Jan 5 '17 at 14:30
• So if 2000=files, 600=intensities, then what's the third dimension of length 2? – Feyre Jan 5 '17 at 14:32
• 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 – ratt4 Jan 5 '17 at 14:56
• I don't see how anyone can help without access to at least one of the data files. – 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:

ListDensityPlot[dat2]

• Woah, it works! thanks a lot! – ratt4 Jan 5 '17 at 17:46
• @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. – yohbs Jan 5 '17 at 17:49