|
From: theozh <th...@gm...> - 2018-11-07 07:14:02
|
sometimes, data curves are available in rows and since gnuplot requires data in columns you would have to transpose your data, correct?
Of course, you can transpose your data with external tools (Python, awk, ...), however, in some cases it might be easier to do this in gnuplot.
I am not aware of a function in gnuplot which plots rows or a function which transposes data.
So, I created the script below.
I think it is neither very elegant nor efficient, but is seems to work.
However, if you have to load the data from a file and transpose it this file needs to be loaded "Rows x Cols" times for every datapoint. Is it like that or will the file be kept in memory? This will be problematic if you have to load the data from a slow network drive.
If anybody has a better solution please let me know.
The script below will 1) create some dummy data 2) print the data 3) transpose it 4) print the transposed data
### transpose data
reset session
# create some dummy data
Rows = 5
Cols = 7
set print $Data
LINE = sprintf("%gx%g\t",Rows,Cols)
# create header columns
do for [j=1:Cols] {
LINE = LINE.sprintf("x[%g]",j)
if (j<Cols) {LINE = LINE."\t"}
}
print LINE
do for [i=1:Rows] {
LINE = ""
do for [j=1:Cols] {
LINE = LINE.sprintf("%g", (i-1)*Cols + j)
if (j<Cols) {LINE = LINE."\t"}
}
LINE = sprintf("t[%g]\t",i).LINE
print LINE
}
set print
print $Data
# end dummy data
# transpose data
set autoscale # autoscale before stats
stats $Data u 0 nooutput
set table $Dummy
set print $Transposed
do for [i=1:STATS_columns] {
LINE = ""
do for [j=0:STATS_records-1] {
plot $Data u (a=stringcolumn(i),i) every ::j::j with table
LINE = LINE.sprintf("%s", a)
if (j < STATS_records-1) {LINE = LINE."\t"}
}
print LINE
}
set print
unset table
print $Transposed
# end transpose data
|