Line plot in GnuPlot where line width is a third column in my data file?

你。 提交于 2020-05-29 04:08:09

问题


I have a datafile that has three columns :

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

where the first column is my X value, the second column is my Y value, and the third column is the line width. I'd like for each line segment to be plotted according to the third column line width.

I tried:

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

But I get undefined variable: var error.

Is this possible in gnuplot?

Thanks.


回答1:


If you define column 3 as the linewidth between points n and n+1 (so the value of col. 3 of the row will be ignored) you can cheat:

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

You need the first plot for[i=0:0] to 'initialize' variable 'alma'.




回答2:


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

This produces the correct line width (as opposed to the “line height”, as in the answer to a related question). I have no clue how to make the “lines” match where they join (seems to be impossible without support from inside gnuplot).

(This assumes that the data in the question is in a file varwidth.dat.)



来源:https://stackoverflow.com/questions/37925489/line-plot-in-gnuplot-where-line-width-is-a-third-column-in-my-data-file

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