使用gnuplot

时间:2016-11-29 21:10:45

标签: windows graph gnuplot

我已经制作了一个脚本来使用gnuplot绘制一些线条。我的脚本如下:

#!/usr/local/bin/gnuplot
reset
set terminal wxt
set yrange [0:100]
set xrange [0:100]
unset colorbox
set style arrow 1 nohead lc rgb 'black'
set style arrow 2 nohead lc rgb 'red'
set arrow 1 from 1,10 to 2,10 nohead
plot [0:15][0:22]-0.2*x+7.8
set arrow 1 from 2,15 to 3,15 nohead
plot [0:15][0:22]-0.2*x+12.8
set arrow 1 from 3,20 to 4,20 nohead
plot [0:15][0:22]-0.2*x+17.8

我想绘制所有三条线,但是当我运行它时,我只得到一行作为输出。脚本有什么问题吗?

2 个答案:

答案 0 :(得分:1)

您只需要发出一个plot命令:

#!/usr/local/bin/gnuplot
reset
set terminal wxt
set yrange [0:100]
set xrange [0:100]

set style arrow 1 nohead lc rgb 'black'
set style arrow 2 nohead lc rgb 'red'
set arrow 1 from 1,10 to 2,10 nohead
set arrow 2 from 2,15 to 3,15 nohead
set arrow 3 from 3,20 to 4,20 nohead
plot [0:15][0:22] -0.2*x+7.8, \
    -0.2*x+12.8, \
    -0.2*x+17.8

答案 1 :(得分:0)

不同的箭头必须具有不同的索引。因此,请使用set arrow 1 ...set arrow 2 ...set arrow 3 ...,而不是三次指定set arrow 1 ...

脚本中的其他几点:

  • set style arrow定义的样式将分配给带有arrowstyle关键字的箭头。

所以可以使用它:

set style arrow 1 nohead lc rgb 'black'
set style arrow 2 nohead lc rgb 'red'
set style arrow 3 nohead lc rgb 'green'

set arrow 1 from 1,10 to 2,10 arrowstyle 1
set arrow 2 from 2,15 to 3,15 arrowstyle 2
set arrow 3 from 3,20 to 4,20 arrowstyle 3

plot [0:15][0:22]-0.2*x+7.8  ,\
                 -0.2*x+12.8 ,\
                 -0.2*x+17.8

或者这个:

set arrow 1 from 1,10 to 2,10 nohead lc rgb 'black'
set arrow 2 from 2,15 to 3,15 nohead lc rgb 'red'
set arrow 3 from 3,20 to 4,20 nohead lc rgb 'green'

plot [0:15][0:22]-0.2*x+7.8  ,\
                 -0.2*x+12.8 ,\
                 -0.2*x+17.8
  • 命令set xrange [0:100][0:15]命令中的plot覆盖。 yrange
  • 也是如此
  • 一个情节命令就足够了。
  • colorbox仅在pm3d情节
  • 时需要