gnuplot-具有用户定义厚度的二维图

时间:2018-08-06 12:25:47

标签: gnuplot

我在文本文件x, y, t中有一组sect.txt。第一行代表x1, y1 , t1,第二行代表x2, y2, t1 ...第四行(第三行为空白)为x3, y3, t2,后跟x4, y4, t3。我想绘制一条线,其坐标为x1, y1x2, y2,厚度为t1。类似地,下一行的坐标x3, y3x4, y4的厚度为t2,依此类推,连续n次。使用下面的代码,我能够在gnuplot中绘制2d线,但无法合并厚度。有人可以提出任何建议吗?

   0.0000000000000000        5.0000000000000000   5  
   1084.0000000000000        5.0000000000000000   5 

   542.00000000000000        10.000000000000000   1  
   542.00000000000000        981.00000000000000   1  

   0.0000000000000000        990.50000000000000   2     
   1084.0000000000000        990.50000000000000   2  

   392.00000000000000        1017.5000000000000   4.5  
   692.00000000000000        1017.5000000000000   4.5  

   392.00000000000000        1682.5000000000000   3  
   692.00000000000000        1682.5000000000000   3  

   542.00000000000000        1035.0000000000000    2 
   542.00000000000000        1665.0000000000000    2

代码

 set xlabel "X Axis (Major) "
 set ylabel"Y Axis (Minor) "
 coord="sect.txt"
 set timestamp
 set autoscale keepfix
 set view equal xy 
 plot coord using 1:2 with linespoints

1 个答案:

答案 0 :(得分:0)

据我所知,lw不支持variable关键字,而线条颜色lc也不支持。但是,可以用一个小的“把戏”来做到这一点。想法是首先确定输入文件中的行数,然后首先执行辅助绘图(通过every关键字每行),以将线宽加载到数组中。该数组又用于“真实”绘图中:

fName = 'test.dat'

stat fName nooutput

#number of lines
M = int(STATS_records/2)

array lineWidths[M]

plot \
  for [i=0:M-1] fName every :::i::i u 1:(lineWidths[i+1]=$3,1/0) t '', \
  for [i=0:M-1] fName every :::i::i u 1:2 w l lw lineWidths[i+1] t sprintf("line %d", i+1)

对于您的输入,将产生: enter image description here