使用Gnuplot绘制态密度(DOS)时填充曲线失效问题排查
Gnuplot态密度(DOS)填充曲线不显示问题解决
问题描述
用户使用以下Gnuplot脚本绘制态密度,期望实现曲线与y=0轴之间的填充效果,但实际输出中填充未生效:
set term postscript enhanced colour set output 'dos.ps' # 原脚本此处缺失闭合单引号,为核心语法错误 set key box font 'Helvetica, 12' left center set key at 6,15 set grid set size noratio 1, 0.8 set style fill transparent solid 1.0 noborder set style data filledcurves y1=0 set arrow from 0, graph 0 to 0, graph 1 nohead set xlabel "E-E_f [eV]" font 'Helvetica, 20' set arrow 5 head filled size screen 0.02,13 from -0.5,-17.3 to 0.4,-17.3 lc rgb "black" lw 3 set arrow 6 head filled size screen 0.02,13 from -9.05,5.5 to -9.05,8.4 lc rgb "black" lw 3 set ylabel "Density of states" font 'Helvetica, 20' plot [-5:3] [-10:10] 'dos.dat' using ($1-12.6258):2 with filledcurves lc rgb "red" title "Spin Up", \ 'dos.dat' using ($1-12.6258):($3*-1) with filledcurves lc rgb "#4169E1" title "Spin Down", \ 0.0 lc rgb "black" title '', \ 'dos.dat' with lines lc rgb "black" title '' set output ! ps2pdf -r300 dos.ps ! rm dos.ps ! pdftocairo -png -r 300 dos.pdf
当前绘制效果:
期望绘制效果:
问题原因及解决方案
核心语法错误:输出路径未闭合
原脚本中set output 'dos.ps缺少末尾单引号,导致Gnuplot解析后续命令异常,填充样式等设置无法正常生效,修复后应为set output 'dos.ps'。填充命令的明确性问题
原脚本在plot中使用filledcu缩写可能引发解析歧义,建议写全filledcurves,确保Gnuplot准确识别填充模式。箭头位置超出绘图范围(非填充失效直接原因,影响美观)
脚本中箭头坐标(如-9.05,5.5、-0.5,-17.3)超出了plot [-5:3] [-10:10]的显示范围,这些箭头不会被渲染,可根据需求调整箭头位置或扩大绘图范围。
修正后效果
修复上述问题后重新运行脚本,即可实现曲线与y=0轴之间的填充效果,匹配期望样式。
内容的提问来源于stack exchange,提问作者Binay Limbu
相关产品推荐
相关产品推荐

