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

Gnuplot堆叠双图multiplot配置问题求助

Gnuplot上下堆叠双图配置方案

以下是针对需求修改后的完整Gnuplot代码,同时逐条说明实现逻辑:

# 设置整体图尺寸,需在进入multiplot前执行
set size 0.7, 0.7

# 定义拟合函数(若已提前定义可忽略此段)
f(x) = -0.012*x + 5.27
g(x) = 0.026*x + 2.87

# 开启multiplot,设置2行1列布局,调整边距和子图间距
set multiplot layout 2,1 margins 0.15,0.95,0.1,0.9 spacing 0.05

# ===== 上方子图配置 =====
unset xtics
set xrange [:108]
# 开启垂直网格线
set grid x
plot "haildays_north_south.txt" u 0:4 w line lc rgb "blue" t "POH timeseries north", \
     f(x) w line lc rgb "red" t "f(x) = -0.012x+5.27"

# ===== 下方子图配置 =====
set xtics ("2002" 1, "2004" 13, "2006" 25, "2008" 37, "2010" 49, "2012" 61, "2014" 73, "2016" 85, "2018" 97, "2020" 108)
set xrange [:108]
set yrange [:16]
# 关闭上方子图的垂直网格(按需选择)
unset grid x
# 设置共享y轴标签,通过偏移让它居中于双图之间
set ylabel "Number of haildays per month" offset -3,0
set xlabel "Months (April-September 2002-2019)"
plot "haildays_north_south.txt" u 0:3 w line lc rgb "blue" t "POH timeseries south", \
     g(x) w line lc rgb "red" t "f(x) = 0.026x+2.87"

unset multiplot

需求实现说明

  • 为上方子图添加垂直网格线:绘制上方子图前执行set grid x,仅开启x轴方向的垂直网格;下方子图不需要则用unset grid x关闭。
  • 设置整体图尺寸为0.7,0.7:set size命令必须在进入multiplot模式前执行,参数分别对应画布宽度和高度的比例。
  • 仅保留一个居中于双图之间的ylabel:通过offset参数调整y轴标签的水平位置(示例中offset -3,0可根据实际显示效果微调),仅在下方子图设置ylabel,上方子图不设置即可避免重复。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 20:33:21