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

gnuplot同时绘制数据文件与函数报错:cairolatex终端无法输出到标准输出

解决gnuplot cairolatex终端无法输出到标准输出的问题

问题描述

使用gnuplot 4.6.7搭配MiKTeX-pdfTeX 4.10(MiKTeX 22.7),运行以下gnuplot脚本时触发报错:

原gnuplot脚本

set grid

set xlabel "Entropy"
set ylabel "Amortized work"
set xrange [-0.05:1.05]

set style line 1 linecolor rgb '#516db0' linetype 2 linewidth 5

f(x) = -1.3973 * x ** 2 + 1.3947 * x + 0.5796
F = '$-1.3973 x^2 + 1.3947 x + 0.5796$'

set terminal cairolatex pdf input size 700,700 color colortext
set key opaque box lc "black" linewidth 3

plot 'RatioVerboseData.dat', f(x) 

set output

数据文件RatioVerboseData.dat内容

0.93070 0.290710
0.94060 0.281450
0.95050 0.254771
0.96040 0.241656

报错信息

plot 'RatioVerboseData.dat', f(x)
                              ^
cairolatex terminal cannot write to standard output
"EntropyVerboseData.plt", line 15: util.c: No error

解决方案

报错核心原因是cairolatex终端不支持输出到标准输出,必须明确指定输出文件路径。修改脚本如下:

  1. 在set terminal指令之后、plot命令之前,添加set output并指定输出文件名(例如plot_output.tex)
  2. 保留原脚本末尾的set output用于关闭输出文件

修改后的完整脚本

set grid

set xlabel "Entropy"
set ylabel "Amortized work"
set xrange [-0.05:1.05]

set style line 1 linecolor rgb '#516db0' linetype 2 linewidth 5

f(x) = -1.3973 * x ** 2 + 1.3947 * x + 0.5796
F = '$-1.3973 x^2 + 1.3947 x + 0.5796$'

set terminal cairolatex pdf input size 700,700 color colortext
set output 'plot_output.tex'  # 新增:指定输出LaTeX文件
set key opaque box lc "black" linewidth 3

plot 'RatioVerboseData.dat', f(x) 

set output  # 关闭输出文件

修改后运行脚本,gnuplot会生成指定的.tex文件,随后使用MiKTeX的pdfTeX编译该文件即可得到PDF格式的图表。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 23:31:06