如何在gnuplot中仅绘制红色errorbar并解决误差值过小显示异常?
Gnuplot 仅显示红色误差棒不显示数据点的问题解决
需求是只绘制红色误差棒、不显示数据点,但移除数据点后误差棒显示异常,推测是误差值过小导致。当前使用的代码如下:
set term postscrip eps color set output "result.eps" set errorbars linecolor rgb "red" linewidth 1 plot "sigma.dat" using 1:2:3:4 with errorbars pointtype 0, \ "sigma.dat" using 1:2 with lines
几种可行的实现方法
1. 彻底隐藏数据点,确保误差棒正常渲染
你用了pointtype 0,但部分gnuplot版本里这个设置没法完全隐藏点,甚至会影响误差棒的短横线显示。试试把点大小设为0,同时明确用yerrorbars(针对y方向误差):
set term postscript eps color set output "result.eps" plot "sigma.dat" using 1:2:3:4 with yerrorbars lc rgb "red" lw 1 pt 0 ps 0, \ "sigma.dat" using 1:2 with lines
ps 0(pointsize 0)会彻底隐藏数据点,误差棒的短横线就能正常渲染了。
2. 调大误差棒短横线长度,让小误差更显眼
如果误差值太小导致短横线几乎看不见,可以手动设置短横线的长度:
set term postscript eps color set output "result.eps" # 把误差棒短横线长度设为0.5(单位是字符宽度,可按需调整) set errorbar 0.5 plot "sigma.dat" using 1:2:3:4 with yerrorbars lc rgb "red" lw 1 pt 0 ps 0, \ "sigma.dat" using 1:2 with lines
set errorbar <数值>可以调整短横线长度,让小误差也能清晰显示。
3. 简化代码,避免全局样式冲突
不用全局设置set errorbars,直接在plot命令里指定样式,减少潜在冲突:
set term postscript eps color set output "result.eps" plot "sigma.dat" using 1:2:3:4 with yerrorbars lc "red" lw 1 notitle, \ "sigma.dat" using 1:2 with lines title "数据曲线"
notitle可以去掉误差棒的图例,避免和曲线图例重复。
针对误差值过小的额外技巧
如果误差实在太小,肉眼几乎看不到,可以试试:
- 调整y轴范围,放大误差区域:
set yrange [最小值:最大值](替换成你数据的实际范围) - 对误差值做缩放,比如在using语句里乘一个系数:
using 1:2:($3*10):($4*10)(注意保证数据和误差的逻辑对应)
内容的提问来源于stack exchange,提问作者김정석
相关产品推荐
相关产品推荐

