I have a file with this format
0 R1 R2 R3 R4
w1 I1 I2 I3 I4
w2 I1 I2 I3 I4
w3 I1 I2 I3 I4
with values of radius R and intensity I in many wavelengths w. I want to plot in 2D, the row 1 (the radius) in the x-axis and row 3 in the y-axis (choosing w2).
how plot per lines? not per columns
It's perhaps not the most elegant solution but you could first filter the two lines (the header containing the x-values and the line corresponding to the wavelength of interest), print them side by side, and finally plot this auxiliary data using Gnuplot.
To this end, the strategy would be to create a script called, e.g.,
filter.awk
in the directory from which you want execute Gnuplot with following content:This remembers the x-values from the first line and stores them in an array
x
. The wave length is passed as an command line argument (see below) via the variablew
. If the first column in the data is equal tow
, the script then generates two columns: x-values in the first one, y-values (taken from the current row) in the second one.In Gnuplot you can then use this as:
where
data.dat
would be your input data and the value of100
represents the wave length which is supposed to be filtered.To generalize this, one could for example do:
Here, the plotting command is generated via the
cmd
function which accepts one argument denoting the wave length. The plot command then loops over a "list" of wave lengths and plots them individually with custom title. The statementw+0
is used here to explicitly convert the string value ofw
to a number.One solution is to create a new file with the right format (data in columns). First create a function to read data in your file (see topic "Reading dataset value into a gnuplot variable (start of X series)"):
Thus construct your new file and plot it:
Be sure to delete
newFile.txt
each time you do the process.