GNUPLOT 绘制不在边界限制内的步骤图

GNUPLOT draws step plot not within border restrictions

绘制阶梯图总是会导致结果超出边界。
如何解决这个问题?有任何想法吗?谢谢!

MWE 是:

reset;set term png small size 500,500;set output 'test.png';
set title 'First step is always drawn out of chart borders ?!?';
unset y2tics;set y2range [0:40];set y2tics 10;set yrange [0:40];set ytics 10 mirror;
set style fill solid 1.00 border;
plot 'test.data' using 1:2  notitle with fillsteps lc rgb 'light-goldenrod', \
'' using 1:3 notitle with fillsteps lc rgb 'gray40', \
'' using 1:4 notitle with fillsteps lc rgb 'web-green', \
'' using 1:5 notitle with fillsteps lc rgb 'light-green';

结果是:

使用的软件是:

GNUPLOT 版本 5.2 补丁级别 8

好的,现在我明白你的意思了。看起来像一个小错误(或我们有限的理解)。 我不能马上说出这是为什么,但你可以避免它 通过在包含第一个 x 值的开头添加一行,所有 y-values 都是 0。 如果您不想手动执行此操作,可以使用 gnuplot 自动执行此操作。 但我希望有一个更简单的解决方案。

代码:

### plot with fillsteps
reset session

$Data <<EOD
1    0   0   0   0
1   50  35  30   5
2   55  30  20   5
17  51  44  30  12
20   1   1   1   1
EOD

unset y2tics;set y2range [0:40]
set y2tics 10
set yrange [0:40]
set ytics 10 mirror
set style fill solid 1.00 border
unset key

plot $Data u 1:2 w fillsteps lc 'light-goldenrod', \
        '' u 1:3 w fillsteps lc 'gray40', \
        '' u 1:4 w fillsteps lc 'web-green', \
        '' u 1:5 w fillsteps lc 'light-green'
### end of code

结果:

添加:(自动复制第一行,解决错误(!?))

为了解决这个问题(我称之为意外或错误),您需要自动复制第一行。使用外部工具肯定会有不同的简单方法,但是,这不能保证 platform-independence。因此,这是几种可能的 gnuplot-only 解决方案之一。

  1. 将您的文件放入数据块(此处:$Data)(参见 gnuplot: load datafile 1:1 into datablock
  2. $Data 的第一行打印到新数据块中(此处:$Data2)确保第一行不是 header 或注释行,即打印第一行数据行.
  3. 再次将完整的数据块 $Data 附加到 $Data2

数据: (Test.dat)

1   50  35  30   5
2   55  30  20   5
17  51  44  30  12
20   1   1   1   1

代码:(结果同上)

# https://whosebug.com/a/67151340/7295599
### plot with filledcurves
reset session

FileToDatablock(f,d) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
                       sprintf('< echo   %s ^<^<EOD  & type "%s"',d,f) : \
                       sprintf('< echo "\%s   <<EOD" & cat  "%s"',d,f)     # Linux/MacOS

FILE = 'Test.dat'
load FileToDatablock(FILE,'$Data')

set print $Data2
    print $Data[1]   # only first line
    print $Data
set print

unset y2tics;set y2range [0:40]
set y2tics 10
set yrange [0:40]
set ytics 10 mirror
set style fill solid 1.00 border
unset key

plot $Data2 u 1:2 every ::0::0 w fillsteps lc 'light-goldenrod', \
        '' u 1:2 w fillsteps lc 'light-goldenrod', \
        '' u 1:3 w fillsteps lc 'gray40', \
        '' u 1:4 w fillsteps lc 'web-green', \
        '' u 1:5 w fillsteps lc 'light-green'
### end of code