plot 10 line sof 1000 values on gnuplot

▼魔方 西西 提交于 2020-01-16 18:21:29

问题


I have a data file with 10 lines with 1000 values each line and I'm trying to plot this values with this script

#!/usr/bin/gnuplot -persist

 plot "data.dat" using [1:1000] title "" with lines

but I get this error

plot "data.dat" using [1:1000] title "" with lines
                      ^
"./plot.sh", line 3: invalid expression 

How can I indiate a interval form the first value to the 1000 value?I't posible to set a diferent random clor to every line?


回答1:


As @vaettchen pointed out, gnuplot wants data in columns and plotting rows is not straightforward. So, best would be if your data was transposed. Unfortunately, gnuplot has no function to transpose data. So, you have to use external tools to transpose your data.

Although, if your data is 10 lines with 1000 values each, i.e. a strict 10x1000 matrix, you could do something with gnuplot only (see below). However, if your data is not a strict matrix, e.g. one line has more or less values or one value missing the method below won't work.

The following example (just 5 lines with 7 values each) illustrates plotting columns and plotting rows.

### plotting columns and rows
reset session
set colorsequence classic

$Data <<EOD
11  12  13  14  15  16  17
21  22  23  24  25  26  27
31  32  33  34  35  36  37
41  42  43  44  45  46  47
51  52  53  54  55  56  57
EOD

# get the number of rows
stats $Data u 0 nooutput
RowCount = STATS_records

# do the plot
set multiplot layout 1,2
    set title "Plotting columns"
    set xlabel "Row no."
    set xtics 1
    # plot all columns from 1 to *(=autodetection)
    plot for [i=1:*] $Data u ($0+1):i w lp pt 7 not

    set title "Plotting rows"
    set xlabel "Column no."
    # plot all rows
    plot for [i=0:RowCount-1] $Data matrix u ($1+1):0 every :::i::i w lp pt 7 not
unset multiplot
### end of code

Which results in:



来源:https://stackoverflow.com/questions/53895866/plot-10-line-sof-1000-values-on-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!