如何在GNUplot中设置Y轴断裂(0.3-2.3区间)
在GNUplot中实现Y轴断裂并标注的解决方案
以下是适配你现有脚本的完整实现,通过multiplot分上下两个子图展示Y轴区间,同时添加断裂标记:
reset session $Singlets <<EOD 0 0.000 1 2.652 2 2.704 3 2.842 EOD $Triplets <<EOD 1 2.511 2 2.547 3 2.580 4 2.618 5 2.826 6 2.836 EOD unset xtic set key noautotitle set ylabel "Energy / eV" vector_scale = 0.5 # 向量长度缩放因子 triplet_x_offset = 0.75 # 单重态与三重态的水平间距 # 配置双图布局,上下排列,预留断裂标记空间 set multiplot layout 2,1 rowsfirst spacing 0.1 # -------------------------- 上半子图:Y轴范围2.3~3 -------------------------- set yrange [2.3:3] set ytics 2.3,0.1,3 set border 1+2+4 # 仅显示左、上、右边框,隐藏底部边框避免重复 set offset 0.25,0.25,0,0 # 绘制上半区间数据(过滤Y<2.3的点) plot $Singlets u (0):($2 >=2.3 ? $2 : NaN):(1*vector_scale):(0) w vectors lw 2 lc "red" nohead, \ '' u (0):($2 >=2.3 ? $2 : NaN):(sprintf("S_%d", $1)) w labels offset -1.5,0, \ '' u (0.25):($2 >=2.3 ? $2 : NaN):(sprintf("%.2f", $2)) w labels offset 0,0.5, \ $Triplets u (triplet_x_offset):($2 >=2.3 ? $2 : NaN):(1*vector_scale):(0) w vectors lw 2 lc "blue" nohead, \ '' u (triplet_x_offset+0.50):($2 >=2.3 ? $2 : NaN):(sprintf("T_%d", $1)) w labels offset 1.5,0, \ '' u (triplet_x_offset+0.25):($2 >=2.3 ? $2 : NaN):(sprintf("%.2f", $2)) w labels offset 0,0.50 # -------------------------- 下半子图:Y轴范围0~0.3 -------------------------- set yrange [0:0.3] set ytics 0,0.1,0.3 set border 1+2+8 # 仅显示左、下、右边框,隐藏顶部边框 set offset 0.25,0.25,0,0 unset ylabel # 避免重复显示Y轴标签 # 绘制下半区间数据(过滤Y>0.3的点) plot $Singlets u (0):($2 <=0.3 ? $2 : NaN):(1*vector_scale):(0) w vectors lw 2 lc "red" nohead, \ '' u (0):($2 <=0.3 ? $2 : NaN):(sprintf("S_%d", $1)) w labels offset -1.5,0, \ '' u (0.25):($2 <=0.3 ? $2 : NaN):(sprintf("%.2f", $2)) w labels offset 0,0.5, \ $Triplets u (triplet_x_offset):($2 <=0.3 ? $2 : NaN):(1*vector_scale):(0) w vectors lw 2 lc "blue" nohead, \ '' u (triplet_x_offset+0.50):($2 <=0.3 ? $2 : NaN):(sprintf("T_%d", $1)) w labels offset 1.5,0, \ '' u (triplet_x_offset+0.25):($2 <=0.3 ? $2 : NaN):(sprintf("%.2f", $2)) w labels offset 0,0.50 # -------------------------- 添加断裂标记 -------------------------- # 在Y轴位置绘制双斜杠,可根据X范围微调坐标 set arrow from -0.25,0.3 to -0.15,0.3 lc "black" lw 2 set arrow from -0.22,0.32 to -0.18,0.28 lc "black" lw 2 set arrow from -0.22,0.28 to -0.18,0.32 lc "black" lw 2 unset multiplot
关键说明:
- 双图布局:通过
multiplot layout 2,1创建上下两个子图,spacing 0.1预留断裂标记的显示空间。 - 数据过滤:使用三元表达式
($2 >=2.3 ? $2 : NaN)和($2 <=0.3 ? $2 : NaN)让每个子图仅显示对应Y区间的数据,避免无效点干扰。 - 边框控制:分别隐藏上下子图的底部/顶部边框,使断裂处视觉上更连贯。
- 断裂标记:用三条箭头绘制双斜杠,坐标可根据你的X轴实际范围调整(当前适配原脚本的
offset设置)。
内容的提问来源于stack exchange,提问作者farmaceut
相关产品推荐
相关产品推荐

