GnuPlot中的线图,其中线宽是我数据文件中的第三列?

时间:2016-06-20 14:48:08

标签: plot graph gnuplot

我有一个包含三列的数据文件:

1 1.0 1
2 1.5 2
3 0.0 3
4 1.2 2.5
5 1.0 1
6 1.1 5

其中第一列是我的X值,第二列是我的Y值,第三列是线宽。我想根据第三列线宽绘制每个线段。

我试过了:

plot 'file1.dat' using 1:2:3  with lines lw var

但是我得到了未定义的变量:var error。

这可以在gnuplot中使用吗?

感谢。

2 个答案:

答案 0 :(得分:4)

如果将第3列定义为点n和n + 1之间的线宽(因此将忽略该行第3列的值),您可以作弊:

stat 'file1.dat'
n=STATS_records
plot for [i=0:0] 'file1.dat' using 1:2:(alma=$3) every ::i::i w l lc 1 lw 1
plot for [i=0:n-1] 'file1.dat' using 1:2:(alma=$3) every ::i::i+1 w l lc 1 lw alma notitle

OR

plot 'file1.dat' u 0:1
n=GPVAL_DATA_X_MAX
plot for [i=0:0] 'file1.dat' using 1:2:(alma=$3) every ::i::i w l lc 1 lw 1
plot for [i=0:n] 'file1.dat' using 1:2:(alma=$3) every ::i::i+1 w l lc 1 lw alma notitle

enter image description here

您需要第一个plot for[i=0:0]来'初始化'变量'alma'。

答案 1 :(得分:0)

stat 'varwidth.dat' nooutput
n=STATS_records; prex=0; prey=0; SC=2    # How y-axis is expanded relative to the x-axis
plot for [i=0:n-1] for [try=0:1] '' using 1:((try==0?dx=$1-prex:1),(try==0?sl=($2-prey)/(dx==0?1:dx):1),(try==0?prex=$1:1),(try==0?prey=$2:1),$2+(w=$3/80*sqrt(1+(SC*sl)**2))/2):($2-w/2) every ::i::i+1 w filledcurves lc 1 notitle

这会产生正确的线宽(与the answer to a related question中的“线高”相对)。我不知道如何使“线”与它们连接的位置匹配(如果没有gnuplot内部的支持,这似乎是不可能的)。

(这假设问题中的数据位于文件varwidth.dat中。)
enter image description here

相关问题