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

Gnuplot生成自由能图时红蓝实线分裂问题求助

Gnuplot自由能图线条分裂问题修复

问题现象

此前运行正常的自由能图Gnuplot脚本,在macOS Ventura 13.2 + Gnuplot 6.0环境下,红色与蓝色的连接实线分裂成多条断裂线段,无法形成完整折线。

问题原因

  1. 表头行未跳过:Gnuplot 6.0对数据块读取逻辑有调整,原脚本绘制连接向量的部分未跳过数据块第一行表头,表头文本被当作数值处理后产生NaN,导致向量绘制中断。
  2. 循环范围错误:数据文件仅包含2个数据块(索引0和1),但原脚本循环范围设为i=0:2,会额外执行一次空数据块绘制,可能引发异常。

修复后的脚本

###subblocks to free energy diagrams###

set terminal emf font "Sans Bold,25" enhanced
set terminal emf size 620,530
makebold(text) = sprintf("{/:Bold %s}", text)
set border 15 front lt black linewidth 3.000 dashtype solid
set xlabel "Reaction Coordinate"
set xrange [-0.2:5.2]
set xtics nomirror scale 0
set ylabel "Free Energy (eV)"
set ylabel offset character 4.5,-3.0,0 font "Sans Bold,25" enhanced
set xlabel offset character 0,0.6,0 font "Sans Bold,25" enhanced
set yrange[-5:0.4]
set ytics in nomirror font "Sans Bold,25" enhanced
set key noautotitle samplen 2
set key enhanced
set errorbars 0
dx = 0.2
myFileOut(s) = sprintf("%s.emf",s)
myTitle(s) = sprintf("%s",s)

inputFiles = '/Users/total.dat'
outputDirs = "/Users//Free-Energy-2/"

# 修正循环范围:匹配实际2个数据块
do for [i=0:1] {
    stats inputFiles index i every ::::0 u (s=strcol(4),0) nooutput
    set output outputDirs.myFileOut(s)
    set title myTitle(s) offset 0,-0.93, 0

    plot inputFiles  index i u 0:2:(dx):xtic(makebold(strcol(1))) w xerr lc "blue" lw 3 ps 0 ti columnheader(2), \
    ''  index i u 0:3:(dx)         w xerr lc "red"  lw 3 ps 0 ti columnheader(3), \
    # 添加every ::1跳过第一行表头
    x1=y1=NaN ''  index i every ::1 u (x0=x1,x1=$0,x0-1+dx):(y0=y1,y1=$2,y0):(1-2*dx):(y1-y0) w vec dt 4 lc "blue" nohead, \
    x1=y1=NaN ''  index i every ::1 u (x0=x1,x1=$0,x0-1+dx):(y0=y1,y1=$3,y0):(1-2*dx):(y1-y0) w vec dt 4 lc "red" nohead
}
set output   # close the last file
### end of script

说明

  • 核心修改:在绘制红蓝连接向量的两行命令中添加every ::1,确保跳过每个数据块的第一行表头,仅处理有效数值行。
  • 循环范围从i=0:2改为i=0:1,匹配数据文件中实际的2个数据块,避免无效循环。
  • 原始数据文件格式无需修改,保持如下即可:
"Reaction Coordinate"  "0 V"   "0.40 V" "FeZn (7, 9)"
O_{2}                   0.00   -2.29
O@^*_{2}               -0.03   -2.31
OOH^*                  -1.05   -3.51
O^*                    -1.54   -4.18
OH^*                   -4.30   -4.92
H_{2}O                 -4.92   -4.92


"Reaction Coordinate"  "0 V"   "0.30 V" "FeZn (1, 9)"
O_{2}                   0.00   -2.29
O@^*_{2}               -0.03   -2.21
OOH^*                  -1.05   -3.51
O^*                    -1.54   -4.18
OH^*                   -4.30   -4.92
H_{2}O                 -4.92   -4.92

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 17:25:59