我在Gnuplot中创建重叠图,因为我混合了法线图和参数图(以及pm3d贴图和参数曲面).除了一件事之外,这种方法效果很好:如果两个图都有标题,则图例通常会重叠.典型示例如下所示:
#legends.gp
set term pngcairo enhanced color linewidth 1.5 dashed dashlength 1.4 rounded
set output "legends.png"
set title "legends test"
set multiplot
# make a box around the legend
set key box
set border 15 lw 1
# fix the margins, this is important to ensure alignment of the plots.
set lmargin at screen 0.15
set rmargin at screen 0.98
set tmargin at screen 0.90
set bmargin at screen 0.15
set xlabel "x"
set ylabel "sin(x)"
set xrange[0:2*pi]
set yrange[-1:1]
set grid x y
# add single tic at 0.62
set xtics add ("x0" 0.62)
# main plot command
plot sin(x) title "sinus"
# turn everything off
set format x "" #numbers off
set format y ""
set xlabel "" #label off
set ylabel ""
set border 0 #border off
unset xtics #tics off
unset ytics
unset grid #grid off
unset title #title off
#plot vertical line at 0.62
set parametric
plot 0.62,t ls 2 lw 2 title "parametric Line"
unset parametric
unset multiplot
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,是否有一种简单的,主要是自动的方式来创建多个图的单个图例?
PS抱歉,我最终通过展示更多功能使示例文件变得更加复杂,希望对未来的读者有所帮助.
mgi*_*son 12
这是一个非常脏的黑客,对我有用.更改:
plot sin(x) title "sinus"
Run Code Online (Sandbox Code Playgroud)
至:
plot sin(x) title "sinus",NaN w l ls 2 lt 2 title "parametric line"
Run Code Online (Sandbox Code Playgroud)
然后绘制没有标题的参数线(例如,notitle而不是title "parametric line").
这是有效的,因为gnuplot在绘图时会忽略NaN - 基本上我们在上面绘制的第二件事只是在图例中添加了一个元素.我指定线型等与参数图线型/类型相同,以便它在图例中正确显示.据我所知,这是做这样的事情的唯一方法......
当然,您可以编辑它,以便两者都参数化绘制并放弃整个多槽业务...
set xrange [0:2*pi]
set yrange [-1:1]
set parametric
set trange [-10:10]
plot t,sin(t) title "Hello", 0.62,t title "World"
Run Code Online (Sandbox Code Playgroud)
这可能是"更清洁"的解决方案......(但使用gnuplot"魔法"的工作效果较差)