Gnuplot 图形在图像顶部的透明应用

Application of Gnuplot figure as transparent on top of image

我想在 Gnuplot 中将 png 图的顶部绘制为透明且没有轴。如果能把图例放在那里就好了。 它的代码基于我在 gnuplot here

中的许多讨论
set xrange [2014:2050]; set yrange [40:125]; set datafile separator " -"; 
set key autotitle columnhead; 
set terminal qt size 560,270;  
set offset 1,1,0,0; d(x) = -0.504 * x + 1097.984; 
c(x) = 83.3; inc(x) = 0.439 * x - 800.65; 
plot d(x) t "Decreasing -0.5\%/yr", c(x), inc(x) t "Increasing +0.5\%/yr", for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror;

产生这个数字

我想将其应用到此图中的 (2014, 83.3) 处,或者只是大致命中起点。 图源:芬兰 2030 年能源愿景,VTT 和 p. 25 here

根据 Christoph 的评论和他的回答进行尝试 here

可读代码

set terminal qt size 560,270; 
set margins 0,0,0,0;
set multiplot; 

# Just plotting here 
set xrange [2014:2050]; 
set yrange [40:125]; 
set datafile separator " -"; 
set key autotitle columnhead;  
set offset 1,1,0,0; 
d(x) = -0.504 * x + 1097.984; 
c(x) = 83.3; inc(x) = 0.439 * x - 800.65; 
plot d(x) t "Decreasing -0.5\%/yr", c(x), inc(x) t "Increasing +0.5\%/yr", for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror; 

set tmargin at screen 0.2; 
set bmargin at screen 0.15; 
unset border; unset tics; 
unset key;  
set autoscale xy; 
plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage; 
unset multiplot;

这里的图片是kulutus_energia_suomi_90_30.png,和正文里一样。

想要输出草稿

One-liner

set terminal qt size 560,270; set margins 0,0,0,0; set multiplot; set xrange [2014:2050]; set yrange [40:125]; set datafile separator " -"; set key autotitle columnhead; set offset 1,1,0,0; d(x) = -0.504 * x + 1097.984; c(x) = 83.3; inc(x) = 0.439 * x - 800.65; plot d(x) t "Decreasing -0.5\%/yr", c(x), inc(x) t "Increasing +0.5\%/yr", for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror; set tmargin at screen 0.2; set bmargin at screen 0.15; unset border; unset tics; unset key; set autoscale xy; plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage; unset multiplot;

我明白了

好的,给你。

我执行的步骤是:

  1. 将 png 绘制为全尺寸背景图像(我选择终端 window 大小与原始图像完全相同):

    set terminal qt size 845,578
    
    set multiplot
    
    # plot the png as full-size background image
    set margins 0,0,0,0
    set autoscale xfix
    set autoscale yfix
    plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage
    
  2. 检查图像中绘图边界的位置并相应地设置 gnuplots 边距,以便 [2014:2040] 的 xrange 位于图像中的正确位置。对于 yranges,我使用了与 png 相同的颜色(顶部可能是 110)。

完整的脚本是

set terminal qt size 845,578

set multiplot

# plot the png as full-size background image
set margins 0,0,0,0
set autoscale xfix
set autoscale yfix
plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage

# now plot the lines on top
height = 578.0
width = 845.0
# borders in pixel
left = 50.0
right = 646.0
top  = 515.0
bottom = 96.0

set tmargin at screen top/height
set bmargin at screen bottom/height
# get the position of 2014 on the png, assumes that left is 1990 and right is 2040
set lmargin at screen left/width + (right - left)/width * 24.0/50.0
set rmargin at screen right/width

set xrange [2014:2040]
set yrange [0:110]
set datafile separator " -"
d(x) = -0.504 * x + 1097.984
c(x) = 83.3
inc(x) = 0.439 * x - 800.65
unset key
unset tics
unset border
plot d(x) t "Decreasing -0.5\%/yr" lw 2, \
     c(x) lw 2, \
     inc(x) lw 2 t "Increasing +0.5\%/yr", \
     for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror

unset multiplot

有了结果

我从那里拿了数据文件,不知道对不对。