Gnuplot将自动缩放xmax设置为始终与y2轴保持间隙

时间:2018-03-31 16:31:20

标签: gnuplot

我有一个gnuplot脚本,工作正常。我正在绘制点右边的最后一个点标签,但x轴末端的空格总是在变化,我还没有弄清楚如何保持一致的空间,以便标签始终可见。

数据文件是这样的,有100个数据点:

171030 784750
171031 787000
171101 773000
171102 798000
171103 784000
171106 794000
171107 781000
171108 785000
171109 788000
171110 794000
171113 793125
171114 795000
171115 795000
171116 794000
171117 776000
...

这是我的剧本:

set term pngcairo size 766,400 enhanced
set output outfile

set xdata time
set timefmt "%y%m%d"
flabel(y)=sprintf("$%'.0f", y)

set format y "%'.0f"

set xtics nomirror
set ytics nomirror

set border 3 # Draw only the left and bottom

set grid linewidth 1
set grid linecolor "#222222"

pic_color="#4682B4"

set autoscale xfixmin

plot infile using 1:2 with lines linewidth 2 linecolor rgb pic_color notitle , \
infile every ::99 using 1:2:(flabel($2)) with labels point pointtype 7 linecolor rgb pic_color offset character 4,character 0 textcolor rgb pic_color notitle

我用:

运行它
gnuplot -e "infile='171030.dat';outfile='171030.png'" script.gp

我尝试使用set autoscale xfixmax,但它删除了空格,我无法找到如何将其设置为固定金额。

如果我将xmax提交给autoscale,有时会留下足够的空间来显示标签,但有时却没有。

我在评论中尝试了Christoph的建议,但没有结果:

没有自动缩放:

# set autoscale xfixmin
set offsets graph 0, 0.1, 0, 0

enter image description here

使用自动缩放xfix:

set autoscale xfix
set offsets graph 0, 0.1, 0, 0

enter image description here

使用自动缩放xfixmin:

set autoscale xfixmin
set offsets graph 0, 0.1, 0, 0

enter image description here

无论我使用什么值来获得正确的偏移,或者我使用set offsets graph 0, 0.1, 0, 0offsets 0, 0.1, 0, 0,或者我只是将其保留为offsets,结果都是相同的。

1 个答案:

答案 0 :(得分:2)

要在数据文件中涵盖的范围内扩展x轴的范围,例如20%,请使用

set autoscale xfix
set offsets 0, graph 0.2

如果您希望将范围扩展固定数量,例如10天,请使用

set autoscale xfix
set offsets 0, 10*24*60*60