print cvs with decription column and multiple rows

Viewed 56

i've got a csv file with this content (Row = Title + 10 Values, Row = Line in chart) column-count is known (but would be great if only the Title is needed and value count is open (but same for all rows)), row count is open

Test1;0,051;0,040;0,051;0,052;0,051;0,049;0,051;0,052;0,059;0,044
Test2;0,016;0,016;0,016;0,019;0,021;0,021;0,021;0,021;0,022;0,022
Test3;0,216;0,200;0,210;0,205;0,205;0,205;0,203;0,206;0,205;0,204

result in LibreOffice

enter image description here

now i want to print it with gnuplot

i tried it with

set xrange [1:10]
set yrange [0:2]
plot for [row=0:*] 'test.csv' matrix every :::row::row with lines

but that only gives me several error messages

"gnuplot.txt" line 7: warning: matrix contains missing or undefined values
"gnuplot.txt" line 7: warning: matrix contains missing or undefined values
"gnuplot.txt" line 7: warning: matrix contains missing or undefined values
"gnuplot.txt" line 7: warning: matrix contains missing or undefined values

would be nice if someone can give me a hint

1 Answers

Unfortunately, gnuplot doesn't like data in rows and doesn't have a transpose function. I guess there is a way to plot rows with matrix as you tried, but currently I don't see a direct way to include the rowheaders as key entry.

So, either you use an external tool and transpose your data or you use the cumbersome gnuplot-transpose-attempt below and then plot columns. At least, this should work for Linux as well as for Windows without the installation of extra tools.

Your decimal sign is ,. Since my standard decimalsign is ., I had to set:

set decimalsign locale 'french'   # or 'german' might also work

Data: test.csv

Test1;0,051;0,040;0,051;0,052;0,051;0,049;0,051;0,052;0,059;0,044
Test2;0,016;0,016;0,016;0,019;0,021;0,021;0,021;0,021;0,022;0,022
Test3;0,216;0,200;0,210;0,205;0,205;0,205;0,203;0,206;0,205;0,204

Code:

### plot row data with rowheader as key entry
reset session

myFile = 'test.csv'

set datafile separator ';'
set decimalsign locale 'french'   # or 'german' should also work

# transpose data
stats myFile u 0 nooutput
set table $Dummy
    set print $DataTransposed
        do for [i=1:STATS_columns] {
            LINE = ''
            do for [j=0:STATS_records-1] {
                plot myFile u (a=stringcolumn(i)) every ::j::j with table
                LINE = LINE.sprintf('%s', j < STATS_records-1 ? a.";" : a)
            }
        print LINE
        }
    set print
unset table
undefine $Dummy

plot for [i=1:STATS_records] $DataTransposed u ($0+1):i w l ti columnheader
### end of code

Result:

enter image description here

Related