如何将用户定义的图例附加到 gnuplot 中的现有图例

How to append user defined legend to existing legend in gnuplot

我用 gnuplot 创建了下面的图表,但现在我想向图例(标题)添加不在绘图数据中的额外值。

我用set arrow画竖线,加标签标识。

set label "Ef" at (Ef+0.5),-20
#some other code
plot

set style line 11 lc rgb 'black' lt 1 dt "-" lw 1 pt 5 ps 1.5 pi 4  # --- black dashed
set style arrow 1 nohead front  ls 11
set arrow arrowstyle 1 from Ef,GPVAL_DATA_Y_MIN to Ef,GPVAL_DATA_Y_MAX
replot

Ef 是一个虚拟变量(在这种情况下 Ef = 5)

但我想用虚线将 Ef 添加到图例中。

我该怎么做?

Gnuplot 一次绘制整个图,因此无法向现有图添加内容。因此,我们必须 "trick" 将其绘制为该行开头的图例条目。

最好的方法是绘制一个未定义的函数。当 gnuplot 遇到未定义的点时,它只是跳过它们,因此绘制函数 1/0 将导致没有点被绘制。

考虑

set arrow 1 from 2,graph 0 to 2,graph 1 lt 0 nohead
plot [-5:5][-2:2] sin(x) t "Sine", 1/0 t "Extra"

这将为该虚线添加一个图例条目,但 plot 命令不会绘制这样一条线。