2

我有这个简单的自包含 gnuplot 脚本:

set terminal png size 400,300
set output 'test.png'

unset key

set xrange [30:50]

$data << EOD
42, 5.7
44, 8.1
46, 8.9
48, 9.2
50, 9.3
EOD

plot "$data" using 1:2 smooth csplines, \
     "$data" using 1:2 with points

输出中的点和csplines曲线都显示得很好:

gnuplot 输出 1

但是现在观察当我通过将xrange线更改为来反转 x 轴方向时会发生什么:

set xrange [50:30]

其他一切都保持不变,csplines现在输出中缺少曲线,而点仍然正确显示:

在此处输入图像描述

如何csplines在第二种情况下显示曲线?
(即从右到左的轴。)

4

1 回答 1

1

确实看起来输出并不理想。使用 Gnuplot 5.0.6,我得到一个空图,如问题所示,而使用 Gnuplot 5.2.2,该图如下所示: 在此处输入图像描述

作为修复,可以先构建插值,将其保存set table到文件中,然后以“相反”的顺序将所有内容绘制在一起:

unset key

set xrange [30:50]

$data << EOD
42, 5.7
44, 8.1
46, 8.9
48, 9.2
50, 9.3
EOD

set table 'meta.csplines.dat'
plot "$data" using 1:2 smooth csplines
unset table

set xrange [50:30]
plot 'meta.csplines.dat' using 1:2 w l lw 2, \
     "$data" using 1:2 with points

这会产生:

在此处输入图像描述

编辑:

set table命令可以与数据块结合使用,以避免创建临时文件(如果需要):

unset key

set xrange [30:50]

$data << EOD
42, 5.7
44, 8.1
46, 8.9
48, 9.2
50, 9.3
EOD

set table $meta
plot "$data" using 1:2 smooth csplines
unset table

set xrange [50:30]
plot "$meta" using 1:2 w l lw 2, \
     "$data" using 1:2 with points
于 2018-02-05T11:11:37.837 回答