gnuplot多图模式(multiplot)箭头层级显示不一致问题求助
gnuplot multiplot模式下箭头层级异常的原因与解决
这不是bug,是对multiplot模式绘图逻辑和back参数的理解偏差,具体原因和解决方法如下:
核心逻辑说明
back参数的本质:set arrow ... back的作用是让箭头绘制在后续执行的绘图命令生成的图形元素下方。在单plot命令中,所有曲线都在箭头定义后绘制,所以箭头能稳定处于所有曲线下方。- multiplot的上下文特性:
multiplot模式下,每个plot命令对应独立的绘图上下文。你在set multiplot前定义的箭头,只会在**第一个plot**中遵循back规则(箭头在曲线下方);第二个plot的曲线会绘制在已存在的箭头上方,导致箭头看起来在前方;第三个plot时,由于图层栈的重置逻辑,箭头又回到了曲线后方。 - 空绘图的影响:当最后一个
plot无有效数据时,它不会生成任何图形元素,箭头的back属性没有后续元素可以“躲在下方”,因此会显示在所有已绘制的子图前方。
正确实现方法
要让每个子图的箭头都稳定显示在曲线后方,需要在每个子图的plot命令前重新定义箭头,并在绘图后清除箭头避免冲突:
dataFile = "question-data.csv" set datafile separator ',' set yrange [0:10] yornothing(l,lc,y) = ((l eq lc)?y:NaN) set multiplot # 子图A set arrow 1 from graph 0, first 4 to graph 1, first 4 nohead back lc rgb "#C0C000" lw 2 set arrow 2 from graph 0, first 5 to graph 1, first 5 nohead back lc rgb "#00FF00" lw 2 set arrow 3 from graph 0, first 6 to graph 1, first 6 nohead back lc rgb "#C0C000" lw 2 plot dataFile every ::1 using 1:(yornothing(strcol(3),"A",$2)) with filledcurves above lc rgb "#0000FF" notitle unset arrow 1,2,3 # 子图B set arrow 1 from graph 0, first 4 to graph 1, first 4 nohead back lc rgb "#C0C000" lw 2 set arrow 2 from graph 0, first 5 to graph 1, first 5 nohead back lc rgb "#00FF00" lw 2 set arrow 3 from graph 0, first 6 to graph 1, first 6 nohead back lc rgb "#C0C000" lw 2 plot dataFile every ::1 using 1:(yornothing(strcol(3),"B",$2)) with filledcurves above lc rgb "#FFA500" notitle unset arrow 1,2,3 # 子图C set arrow 1 from graph 0, first 4 to graph 1, first 4 nohead back lc rgb "#C0C000" lw 2 set arrow 2 from graph 0, first 5 to graph 1, first 5 nohead back lc rgb "#00FF00" lw 2 set arrow 3 from graph 0, first 6 to graph 1, first 6 nohead back lc rgb "#C0C000" lw 2 plot dataFile every ::1 using 1:(yornothing(strcol(3),"C",$2)) with filledcurves above lc rgb "#0000FF" notitle unset arrow 1,2,3 unset multiplot
补充提示
- 也可以通过在每个
plot前执行set arrow ... back,不清除箭头,但需注意箭头ID不要重复,避免覆盖; - gnuplot的
back/front参数是基于绘图命令的执行顺序生效,而非全局图层层级,这在multiplot模式下的表现和单图模式差异明显,需要特别注意。
内容的提问来源于stack exchange,提问作者ulatekh
相关产品推荐
相关产品推荐

