You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在gnuplot中隐藏分段图的指定X轴区段?

解决gnuplot能带图分段X轴隐藏区段的问题

我用附带的gnuplot脚本绘制了能带图,想要设置成分段样式——也就是隐藏Z与X之间、R与M之间的X轴区段。试过multiplot和添加白色填充矩形的方法都没成功,求可行思路,附当前脚本:

delt=0.1

x0 = 0.000
x1 = 0.469 
x2 = 0.939
x3 = 1.603
x4 = 2.027
x5 = 2.496
x6 = 2.965
x7 = 3.629
x8 = 4.053
x9 = 4.477

xmin = x0
xmax = x9+2*delt
ymin = -6.0
ymax = 6.0

set yrange [ymin:ymax]
set xrange [xmin:xmax]
set ylabel '{/Symbol e-e}_{Fermi} (eV)'

set xtics ("{/Symbol G}" x0, "X" x1, "M" x2, "{/Symbol G}" x3, "Z" x4, "R" x5, "A" x6, "Z" x7, "X" x7+delt, "R" x8+delt, "M" x8+2*delt, "A" x9+2*delt)
set mytics 2

set arrow nohead from  x0,ymin to x0,ymax lc rgb "grey" lw 1
set arrow nohead from  x1,ymin to x1,ymax lc rgb "grey" lw 1
set arrow nohead from  x2,ymin to x2,ymax lc rgb "grey" lw 1
set arrow nohead from  x3,ymin to x3,ymax lc rgb "grey" lw 1
set arrow nohead from  x4,ymin to x4,ymax lc rgb "grey" lw 1
set arrow nohead from  x5,ymin to x5,ymax lc rgb "grey" lw 1
set arrow nohead from  x6,ymin to x6,ymax lc rgb "grey" lw 1
set arrow nohead from  x7,ymin to x7,ymax lc rgb "black" lw 1
set arrow nohead from x7+delt,ymin to x7+delt,ymax lc rgb "black" lw 1
set arrow nohead from  x8+delt,ymin to x8+delt,ymax lc rgb "black" lw 1
set arrow nohead from x8+2*delt,ymin to x8+2*delt,ymax lc rgb "black" lw 1

plot  'BAND.dat' u ($1<=x7 ? $1 : 1/0):($2-efermi) w l ls 1 notitle, \
 'BAND.dat' u ($1>x7 && $1<=x8 ? ($1+delt) : 1/0):($2-efermi) w l ls 1 notitle, \
 'BAND.dat' u ($1>x8 ? ($1+2*delt) : 1/0):($2-efermi) w l ls 1 notitle

可行解决思路

方法1:白色矩形覆盖法(修正之前的失败问题)

之前用矩形没成功大概率是没设置层级或者坐标范围不对,直接在脚本里添加前置白色矩形就能覆盖掉要隐藏的X轴区段:

  • 在plot命令前添加两个白色矩形,分别覆盖Z(x7)到X(x7+delt)、R(x8+delt)到M(x8+2*delt)的区间
  • 加上front参数确保矩形在所有绘图元素上方,完全覆盖轴和多余内容

修改后的完整脚本:

delt=0.1

x0 = 0.000
x1 = 0.469 
x2 = 0.939
x3 = 1.603
x4 = 2.027
x5 = 2.496
x6 = 2.965
x7 = 3.629
x8 = 4.053
x9 = 4.477

xmin = x0
xmax = x9+2*delt
ymin = -6.0
ymax = 6.0

set yrange [ymin:ymax]
set xrange [xmin:xmax]
set ylabel '{/Symbol e-e}_{Fermi} (eV)'

set xtics ("{/Symbol G}" x0, "X" x1, "M" x2, "{/Symbol G}" x3, "Z" x4, "R" x5, "A" x6, "Z" x7, "X" x7+delt, "R" x8+delt, "M" x8+2*delt, "A" x9+2*delt)
set mytics 2

# 绘制分段的垂直箭头
set arrow nohead from  x0,ymin to x0,ymax lc rgb "grey" lw 1
set arrow nohead from  x1,ymin to x1,ymax lc rgb "grey" lw 1
set arrow nohead from  x2,ymin to x2,ymax lc rgb "grey" lw 1
set arrow nohead from  x3,ymin to x3,ymax lc rgb "grey" lw 1
set arrow nohead from  x4,ymin to x4,ymax lc rgb "grey" lw 1
set arrow nohead from  x5,ymin to x5,ymax lc rgb "grey" lw 1
set arrow nohead from  x6,ymin to x6,ymax lc rgb "grey" lw 1
set arrow nohead from  x7,ymin to x7,ymax lc rgb "black" lw 1
set arrow nohead from x7+delt,ymin to x7+delt,ymax lc rgb "black" lw 1
set arrow nohead from  x8+delt,ymin to x8+delt,ymax lc rgb "black" lw 1
set arrow nohead from x8+2*delt,ymin to x8+2*delt,ymax lc rgb "black" lw 1

# 添加白色矩形隐藏X轴间隙
set object rectangle from x7, ymin to x7+delt, ymax fillstyle solid 1.0 fillcolor rgb "white" front
set object rectangle from x8+delt, ymin to x8+2*delt, ymax fillstyle solid 1.0 fillcolor rgb "white" front

# 绘制能带数据
plot  'BAND.dat' u ($1<=x7 ? $1 : 1/0):($2-efermi) w l ls 1 notitle, \
 'BAND.dat' u ($1>x7 && $1<=x8 ? ($1+delt) : 1/0):($2-efermi) w l ls 1 notitle, \
 'BAND.dat' u ($1>x8 ? ($1+2*delt) : 1/0):($2-efermi) w l ls 1 notitle

方法2:multiplot分区域绘制

如果矩形法还是有问题,可以用multiplot把图拆成三个独立子图,每个子图对应一个连续区段,中间留空白:

  1. 第一个子图:x范围[x0:x7],显示左侧y轴和对应X轴刻度
  2. 第二个子图:x范围[x7+delt:x8+delt],关闭y轴,只显示中间X轴刻度
  3. 第三个子图:x范围[x8+2*delt:x9+2*delt],关闭y轴,只显示右侧X轴刻度
  4. 用set multiplot layout 1,3配合offset控制子图间距,模拟分段效果

示例框架:

set multiplot layout 1,3 margins 0.1,0.9,0.1,0.9 spacing 0.05,0.0

# 第一个子图
set xrange [x0:x7]
set yrange [ymin:ymax]
set ylabel '{/Symbol e-e}_{Fermi} (eV)'
set xtics ("{/Symbol G}" x0, "X" x1, "M" x2, "{/Symbol G}" x3, "Z" x4, "R" x5, "A" x6, "Z" x7)
set arrow nohead from  x0,ymin to x0,ymax lc rgb "grey" lw 1
set arrow nohead from  x1,ymin to x1,ymax lc rgb "grey" lw 1
set arrow nohead from  x2,ymin to x2,ymax lc rgb "grey" lw 1
set arrow nohead from  x3,ymin to x3,ymax lc rgb "grey" lw 1
set arrow nohead from  x4,ymin to x4,ymax lc rgb "grey" lw 1
set arrow nohead from  x5,ymin to x5,ymax lc rgb "grey" lw 1
set arrow nohead from  x6,ymin to x6,ymax lc rgb "grey" lw 1
set arrow nohead from  x7,ymin to x7,ymax lc rgb "black" lw 1
plot 'BAND.dat' u ($1<=x7 ? $1 : 1/0):($2-efermi) w l ls 1 notitle

# 第二个子图
set xrange [x7+delt:x8+delt]
unset ylabel
set ytics nomirror
set xtics ("X" x7+delt, "R" x8+delt)
set arrow nohead from x7+delt,ymin to x7+delt,ymax lc rgb "black" lw 1
set arrow nohead from  x8+delt,ymin to x8+delt,ymax lc rgb "black" lw 1
plot 'BAND.dat' u ($1>x7 && $1<=x8 ? ($1+delt) : 1/0):($2-efermi) w l ls 1 notitle

# 第三个子图
set xrange [x8+2*delt:x9+2*delt]
unset ytics
set xtics ("M" x8+2*delt, "A" x9+2*delt)
set arrow nohead from x8+2*delt,ymin to x8+2*delt,ymax lc rgb "black" lw 1
plot 'BAND.dat' u ($1>x8 ? ($1+2*delt) : 1/0):($2-efermi) w l ls 1 notitle

unset multiplot

内容的提问来源于stack exchange,提问作者Pascal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 09:14:54