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

gnuplot epslatex终端不显示x轴标签问题求助

问题:Gnuplot epslatex终端生成的图缺失X轴标签

我使用gnuplot的epslatex终端生成绘图,但生成的图中X轴标签"My Label"缺失,以下是我的最小可复现脚本和LaTeX引用代码:

Gnuplot脚本代码

set title font "Monospaced,13"
set grid

f(x) = 5 * log(x) / log(2) 
g(x) = 5 + sqrt(5 + x)

F = '$5 \log_2(x)$'
G = '$5 + \sqrt{5 + x}$'

# set yrange [0:300]
set xrange [0:4000]
set xlabel 'My Label'

set style line 1 linecolor rgb '#a82828' linetype 1 linewidth 5 pointtype 5 pointsize 1.5
set style line 2 linecolor rgb '#516db0' linetype 1 linewidth 5 pointtype 9 pointsize 1.5

plot f(x) title F with lines ls 1, g(x) title G with lines ls 2 

set terminal epslatex background rgb "grey" standalone size 10.0cm,10.0cm color colortext
set output 'RunTimeComparisonTreeIndexed.tex'

set style rect fc rgb "white" fs
set object 1 rectangle from screen 0,0 to screen 1,1 behind
set key left top box lt -1 lw 2 opaque

replot
exit

LaTeX引用代码

\begin{figure}[!h]
\centering
%\setlength{\voffset}{0cm}
%\setlength{\hoffset}{0cm}
\includepdf[pages={1},pagecommand={},width=0.5\textwidth]{RunTimeComparisonTreeIndexed.pdf}
%\setlength{\voffset}{- 10cm}
%\setlength{\hoffset}{-10cm}
\label{fig:rtcti}
\caption{Hello}
\end{figure}

问题原因

问题出在终端设置与绘图命令的顺序:你先执行了plot命令,之后才切换到epslatex终端,最后用replot重新绘制。但gnuplot切换终端时,会重置部分与终端渲染相关的参数(包括坐标轴标签),导致之前设置的xlabel在replot时未生效。

解决办法

有两种可行的修正方式:

方式1:先设置终端,再配置所有绘图参数

将set terminal和set output放在最前面,确保所有绘图设置(包括坐标轴标签)都在目标终端生效后执行:

# 先设置终端与输出文件
set terminal epslatex background rgb "grey" standalone size 10.0cm,10.0cm color colortext
set output 'RunTimeComparisonTreeIndexed.tex'

set title font "Monospaced,13"
set grid

f(x) = 5 * log(x) / log(2) 
g(x) = 5 + sqrt(5 + x)

F = '$5 \log_2(x)$'
G = '$5 + \sqrt{5 + x}$'

set xrange [0:4000]
set xlabel 'My Label'

set style line 1 linecolor rgb '#a82828' linetype 1 linewidth 5 pointtype 5 pointsize 1.5
set style line 2 linecolor rgb '#516db0' linetype 1 linewidth 5 pointtype 9 pointsize 1.5

set style rect fc rgb "white" fs
set object 1 rectangle from screen 0,0 to screen 1,1 behind
set key left top box lt -1 lw 2 opaque

# 直接绘制,无需replot
plot f(x) title F with lines ls 1, g(x) title G with lines ls 2 

exit

方式2:切换终端后重新设置坐标轴标签

如果需要保留原有命令顺序,可在切换终端后重新设置xlabel,确保参数在目标终端中生效:

set title font "Monospaced,13"
set grid

f(x) = 5 * log(x) / log(2) 
g(x) = 5 + sqrt(5 + x)

F = '$5 \log_2(x)$'
G = '$5 + \sqrt{5 + x}$'

set xrange [0:4000]

set style line 1 linecolor rgb '#a82828' linetype 1 linewidth 5 pointtype 5 pointsize 1.5
set style line 2 linecolor rgb '#516db0' linetype 1 linewidth 5 pointtype 9 pointsize 1.5

plot f(x) title F with lines ls 1, g(x) title G with lines ls 2 

set terminal epslatex background rgb "grey" standalone size 10.0cm,10.0cm color colortext
set output 'RunTimeComparisonTreeIndexed.tex'

# 切换终端后重新设置xlabel
set xlabel 'My Label'

set style rect fc rgb "white" fs
set object 1 rectangle from screen 0,0 to screen 1,1 behind
set key left top box lt -1 lw 2 opaque

replot
exit

内容的提问来源于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 20:45:30