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

使用Gnuplot multiplot无法输出二进制文件的解决方法

问题解决思路

报错原因

你遇到的multiplot相关报错,核心是指令顺序错误+不必要的多图模式使用:

  • 你仅需绘制单张图表,却启用了multiplot(多子图模式),该模式下绘图上下文规则和单图完全不同。
  • 你把坐标轴标签、范围设置放在了plot命令之后,这在多图模式下会导致设置无法正确关联到当前绘图,触发上下文冲突错误。

修复方案

方案1:移除多图模式(推荐)

直接删掉set multiplot和unset multiplot,并把坐标轴设置移到plot前,这是单图绘制的标准流程,能彻底解决不稳定问题。

修改后的代码:

set style line 1  lt 1  lw 0.9 pt 1 ps  0.9 lc  rgb "navy"
set style line 2  lt 2  lw 0.9 pt 2 ps  1.1 lc  rgb "red"
set style line 3  lt 3  lw 0.9 pt 3 ps  1.1 lc  rgb "blue"
set style line 4  lt 4  lw 0.9 pt 4 ps  1.1 lc  rgb "olive"
set style line 5  lt 5  lw 0.9 pt 5 ps  1.1 lc  rgb "black"
set style line 6  lt 6  lw 0.9 pt 6 ps  1.1 lc  rgb "gray20"

set terminal postscript eps enhanced
set encoding utf8

# 坐标轴、范围设置移到plot命令之前
set xlabel "x (m)"
set ylabel "h(W/m^2°C)"
set xrange [0:0.04]
set yrange [-500:2000]

plot 'solPIhc10^0.dat' with linespoints title "{/Symbol l^2} = 10^{0}", \
'solPIhc10^1.dat' with linespoints title "{/Symbol l^2} = 10^{1}", \
'solPIhc10^-1.dat' with linespoints title "{/Symbol l^2} = 10^{-1}", \
'solPIhc10^-2.dat' with linespoints title "{/Symbol l^2} = 10^{-2}", \
'solPIhc10^-3.dat' with linespoints title "{/Symbol l^2} = 10^{-3}", \
'solPIhc10^-4.dat' with linespoints title "{/Symbol l^2} = 10^{-4}", \
'solPDhc.dat' with points ls 5 title "h1 (PD)"

方案2:保留多图模式(若后续需扩展子图)

如果确实要使用multiplot,需明确单图布局,并把所有绘图属性设置放在plot之前:

set style line 1  lt 1  lw 0.9 pt 1 ps  0.9 lc  rgb "navy"
set style line 2  lt 2  lw 0.9 pt 2 ps  1.1 lc  rgb "red"
set style line 3  lt 3  lw 0.9 pt 3 ps  1.1 lc  rgb "blue"
set style line 4  lt 4  lw 0.9 pt 4 ps  1.1 lc  rgb "olive"
set style line 5  lt 5  lw 0.9 pt 5 ps  1.1 lc  rgb "black"
set style line 6  lt 6  lw 0.9 pt 6 ps  1.1 lc  rgb "gray20"

set terminal postscript eps enhanced
set encoding utf8

set multiplot layout 1,1  # 明确指定单图布局
set xlabel "x (m)"
set ylabel "h(W/m^2°C)"
set xrange [0:0.04]
set yrange [-500:2000]

plot 'solPIhc10^0.dat' with linespoints title "{/Symbol l^2} = 10^{0}", \
'solPIhc10^1.dat' with linespoints title "{/Symbol l^2} = 10^{1}", \
'solPIhc10^-1.dat' with linespoints title "{/Symbol l^2} = 10^{-1}", \
'solPIhc10^-2.dat' with linespoints title "{/Symbol l^2} = 10^{-2}", \
'solPIhc10^-3.dat' with linespoints title "{/Symbol l^2} = 10^{-3}", \
'solPIhc10^-4.dat' with linespoints title "{/Symbol l^2} = 10^{-4}", \
'solPDhc.dat' with points ls 5 title "h1 (PD)"

unset multiplot

补充说明

有时图表能生成是因为gnuplot的上下文缓存机制偶然兼容了错误的指令顺序,但这种不稳定情况会随数据量、gnuplot版本变化触发报错,按上述规范调整后就能稳定运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 10:53:23