1

I am accessing data from many different files using a .plt file that I wrote. Only a specific domain of each data set is significant. I am trying to plot only the specific domain of each data set onto one graph.

The data in each domain corresponds to a peak. I want to plot each of these peaks, then fit an exponential decay function to the peaks.

Here is the code in my plot file:

set xlabel "Time (ms)"
set ylabel "voltage"

set title "T1 time for Isopropyl Alcohol"
dir='C:\Users\Daniel\Desktop\College\modern lab\gp501-win64-mingw\gnuplot\bin\data files\isoproply_alc_t1\'
unset key
set style data linespoints
x(v, left, right) = (v >= left && v <= right ? v : 1/0)
plot dir.'nmr-t1-isopropyl-dt10' using (x($0*0.01, 3, 7)):1, \
     dir.'nmr-t1-isopropyl-dt50' using (x($0*0.01, 20, 40)):1, \
     dir.'nmr-t1-isopropyl-dt100' using (x($0*0.01, 40, 60)):1, \
     dir.'nmr-t1-isopropyl-dt150' using (x($0*0.01, 70, 80)):1, \
     dir.'nmr-t1-isopropyl-dt200' using (x($0*0.01, 99, 101)):1, \
     dir.'nmr-t1-isopropyl-dt230' using (x($0*0.01, 114, 116)):1, \
     dir.'nmr-t1-isopropyl-dt250' using (x($0*0.01, 124, 126)):1, \
     dir.'nmr-t1-isopropyl-dt270' using (x($0*0.01, 134, 136)):1, \
     dir.'nmr-t1-isopropyl-dt290' using (x($0*0.01, 144, 146)):1, \
     dir.'nmr-t1-isopropyl-dt300' using (x($0*0.01, 149, 151)):1, \
     dir.'nmr-t1-isopropyl-dt320' using (x($0*0.01, 159, 161)):1, \
     dir.'nmr-t1-isopropyl-dt340' using (x($0*0.01, 169, 171)):1, \
     dir.'nmr-t1-isopropyl-dt360' using (x($0*0.01, 178, 183)):1, \
     dir.'nmr-t1-isopropyl-dt400' using (x($0*0.01, 198, 201)):1, \
     dir.'nmr-t1-isopropyl-dt430' using (x($0*0.01, 213, 217)):1, \
     dir.'nmr-t1-isopropyl-dt470' using (x($0*0.01, 233, 236)):1, \
     dir.'nmr-t1-isopropyl-dt580' using (x($0*0.01, 289, 291)):1, \
     dir.'nmr-t1-isopropyl-dt620' using (x($0*0.01, 309, 311)):1, \
     dir.'nmr-t1-isopropyl-dt650' using (x($0*0.01, 324, 326)):1, \
     dir.'nmr-t1-isopropyl-dt700' using (x($0*0.01, 348, 352)):1, \
     dir.'nmr-t1-isopropyl-dt750' using (x($0*0.01, 374, 376)):1, \
     dir.'nmr-t1-isopropyl-dt800' using (x($0*0.01, 399, 401)):1, \
     dir.'nmr-t1-isopropyl-dt850' using (x($0*0.01, 424, 426)):1, \
     dir.'nmr-t1-isopropyl-dt900.2' using (x($0*0.01, 449.5, 451)):1

This gives the proper domain.

Now I want to flip the data points, past some arbitrary x-value, over the y-axis. I want to make them negative.

I tried the flipy command, but this did not work.

Daniel Schulze
  • 147
  • 2
  • 2
  • 8

1 Answers1

1

Gnuplot doesn't support specifying an individual range for every data file in a single plot command. That works only for functions.

You must filter the data in the using statement by giving all points outside of the wanted range the value 1/0 which invalidates the respective point:

left = 3
right = 7
plot 'file.dat' using ($0 > left && $0 < right ? $0 : 1/0):1

To make the command more readably, you can also put the filtering in a function. There are also some other possibilities to improve the readability of your code:

  • Define a variable dir which contains the path to your files. The data file name is then concatenated with this variable by the . operator:

    dir = 'C:\my path\'
    plot dir.'file.dat' ...
    
  • Skipping the key (legend) can be skipped globally with unset key

  • You can set the plotting style for data files globally with set style data linespoints

So your script could look like

set xlabel "Time (ms)"
set ylabel "voltage"
set format y "%s"

set title "T1 time for Isopropyl Alcohol"
dir='C:\Users\Daniel\Desktop\College\modern lab\gp501-win64-mingw\gnuplot\bin\data files\isoproply_alc_t1\'
unset key
set style data linespoints
x(v, left, right) = (v >= left && v <= right ? v : 1/0
plot dir.'nmr-t1-isopropyl-dt10' using (x($0*0.01, 3, 7)):1, \
     dir.'nmr-t1-isopropyl-dt50' using (x($0*0.01, 20, 40)):1, \
     dir.'nmr-t1-isopropyl-dt100' using (x($0*0.01, 40, 60)):1, \
     dir.'nmr-t1-isopropyl-dt150' using (x($0*0.01, 70, 80)):1
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • That worked very well! I got a clear plot with all my peaks. Where should I start so that I can fit an exponential decay function to fit these peaks? (It should look like an envelope encompassing all the data points – Daniel Schulze Jun 27 '15 at 21:54
  • You have to put all the points in your decay curve in one file (or inline dataset) to use "fit". A one-liner:`set table $T1data; replot; unset table; fit I-2*I*exp(-x/T1) $T1data us 1:2 noerr via I,T1` (i assumed inversion recovery ;-) ) You might want to tune the left and right limits of each echo so `x()` only returns a single value. – Karl Jun 28 '15 at 18:01
  • it was inversion recovery! Thanks. I am still having trouble working with gnuplot. I might switch back to mathematica! – Daniel Schulze Jun 28 '15 at 22:26
  • Well, in contrast to mathematica, gnuplot is only a plotting programm and not for data processing. Keep that in mind – Christoph Jun 29 '15 at 07:19