Waterfall Plot
elliottmclean
I need to create a waterfall plot from .dat files that I'm loading up from a folder. At the moment I just select which files I want to be loaded and they are all either individually graphed or all graphed on the same 2D plot which can be very messy with a large number of files. I've had a crack at trying to interpret the example code but can't make much sense of it at the moment and was wondering if there was a simpler way to create a waterfall plot from a series of x and y waves. Ideally what I'm looking for is a log/log waterfall plot of a series of q_val/intensity sets to be able to easy compare them.
Cheers.
Function LoadFiles()
Variable refNum
String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
fileFilters += "All Files:.*;"
Open /D /R /MULT=1 /F=fileFilters refNum
String/G outputPaths = S_fileName // Extract the paths of each of the files and store them in outputPaths
End
Function GraphFiles()
SVAR outputPaths = root:outputPaths // Access global variable outputPaths
if (strlen(outputPaths) == 0)
Print "Cancelled"
else
Variable numFilesSelected = ItemsInList(outputPaths, "\r")
Variable i
for(i=0; i<numFilesSelected; i+=1) // Loop through each of the selected files
String path = StringFromList(i, outputPaths, "\r") // The following 3 lines extracts the file number from the file name
Variable slen = strlen(path)
String filenum = path[slen-8,slen-5]
String columnInfo = ""
columnInfo += "N=" + "q_" + filenum + ";" // Set wave names in columnInfo to be used in /B flag
columnInfo += "N=" + "r_" + filenum + ";"
columnInfo += "N=" + "s_" + filenum + ";"
LoadWave/G/O/D/A/B=columnInfo path // Load waves
string w0 = StringFromList(0, S_wavenames) // Extract data from waves
string w1 = StringFromList(1, S_wavenames)
Wave q_val = $w0
Wave intensity = $w1
display intensity vs q_val
label left "Intensity"
label bottom "q"
ModifyGraph log(bottom)=1,log=1,mode=3,marker=8
endfor
endif
End
Variable refNum
String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
fileFilters += "All Files:.*;"
Open /D /R /MULT=1 /F=fileFilters refNum
String/G outputPaths = S_fileName // Extract the paths of each of the files and store them in outputPaths
End
Function GraphFiles()
SVAR outputPaths = root:outputPaths // Access global variable outputPaths
if (strlen(outputPaths) == 0)
Print "Cancelled"
else
Variable numFilesSelected = ItemsInList(outputPaths, "\r")
Variable i
for(i=0; i<numFilesSelected; i+=1) // Loop through each of the selected files
String path = StringFromList(i, outputPaths, "\r") // The following 3 lines extracts the file number from the file name
Variable slen = strlen(path)
String filenum = path[slen-8,slen-5]
String columnInfo = ""
columnInfo += "N=" + "q_" + filenum + ";" // Set wave names in columnInfo to be used in /B flag
columnInfo += "N=" + "r_" + filenum + ";"
columnInfo += "N=" + "s_" + filenum + ";"
LoadWave/G/O/D/A/B=columnInfo path // Load waves
string w0 = StringFromList(0, S_wavenames) // Extract data from waves
string w1 = StringFromList(1, S_wavenames)
Wave q_val = $w0
Wave intensity = $w1
display intensity vs q_val
label left "Intensity"
label bottom "q"
ModifyGraph log(bottom)=1,log=1,mode=3,marker=8
endfor
endif
End
matrix[][0][i] = q_val[p]
matrix[][1][i] = intensity[p]
September 5, 2017 at 02:09 am - Permalink
Here, you might use the
concatenate
operation to create the matrix of intensities (no q-value).In case they are, are they strictly monotonic and have a common step size?
If so, set the wave scaling for the rows. Columns contain the different files. Otherwise use one x-wave as to display the waterfall using
NewWaterfall
operation. The plot can be modified viaModifyWaterfall
.If the x-waves are not identical, the built-in operation will not work. As solutions, you could resample your data into a matrix or use the poor-mans-waterfall-plot utilizing y-offsets (could be derived from wave statistics, e.g., i/factor*(max(wavemax{ywaves})-min(wavemin{ywaves})).
Here a quick example for the displaying part
newwaterfall mat
modifywaterfall angle=90, axlen=.7
HJ
September 5, 2017 at 02:42 am - Permalink
Thanks for the reply.
I thought at first that the x-waves were all unique but upon looking again I've just realised that they are in fact all the same. They're not very nice numbers to work with I'm not sure if that changes how it need to be done but I've attached a converted txt file so you can see what it looks like. I've got about 150 of those files in a folder and I want to be able to select maybe 10 or so and plot the first column vs second column on a log/log waterfall plot so I can compare the q_val vs intensity for each of the selected files.
I had a crack at doing the poor-mans-waterfall-plot which I'm assuming is the same as a fake waterfall plot but it just looks messy and wanted to see if I could do it properly before resorting back to it.
Cheers.
September 5, 2017 at 10:06 pm - Permalink
And ModifyWaterfall has a parameter to control how front traces hide back traces:
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
September 6, 2017 at 01:04 pm - Permalink
How do wavex and wavez get worked in to the NewWaterfall command? Ideally I want the file numbers to be used as the front-to-back offsets so it's possible identify the plots. I'm assuming I could just make a wave of the all the file numbers used and use the aforementioned wavez.
Cheers.
September 17, 2017 at 07:37 pm - Permalink
Scratch that I answered my own question. Is it at all possible to offset in the z-direction? If I've plotted file numbers 120-130 and then 150 and 151 can I somehow include an offset between the 130 and 150 plots since they are essentially time stamps and would be important in their representation.
Cheers.
September 17, 2017 at 08:58 pm - Permalink