I have a data set that has two groups of data each one with 3 columns. I know that I use plot "dataset.dat" i 0 u 1:2
to plot the second column versus the first column in the first set of data (index starts with zero), or plot "dataset.dat" i 1 u 2:3
to plot the third column versus the second column in the second set of data. But what if I want to plot the second column of index 1 versus the second column of index 0?, is that possible? or do I have to put them contiguously in the same index. I have search in the documentation but isn't mentioned there. Thanks for your help.
This is basically a data (re-)arrangement challenge. You could rearrange your data with whatever external tool, but in principle you can also do it somehow with gnuplot.
One possible solution would be to place your y-values (from index 1) in a separate datablock (here; $myY
) and in the final plot command address it by datablock line-index, which starts from 1 and requires a integer number, that's why it is $myY[int($0+1)]
. Furthermore, you need to convert it into a (floating point) number via real()
, check help real
. The assumption is that the subblocks have the same length.
Code:
### plot x and y from different indices
reset session
$Data <<EOD
11 12 13
21 22 23
31 32 33
111 112 113
121 122 123
131 132 133
EOD
set table $myY
plot $Data u 2 index 1 w table
unset table
unset key
plot $Data u 2:(real($myY[int($0)+1])) index 0 w lp pt 7
### end of code
Result: