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

Gnuplot绘制含时间轴曲线并添加最值标签问题求助

修正后的Gnuplot命令及解释

你的原始命令中,标签的x坐标使用了STATS_index_min和STATS_index_max(即最值所在的行号),但由于x轴是时间格式,行号无法对应到正确的时间位置,导致标签被绘制在可视区域之外。以下是修正后的完整命令:

reset
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"

# 获取最值及其所在行号
stats "source.txt" using 3 nooutput

# 捕获最值对应的时间x值
min_x = NaN
max_x = NaN
plot "source.txt" using (idx = $0 + 1; 
                         if (idx == STATS_index_min) min_x = timecolumn(1); 
                         if (idx == STATS_index_max) max_x = timecolumn(1); 
                         $1):3 notitle with lines

# 设置x轴显示格式
set format x "%d-%b\n%H:%M"

# 绘制最值标签(使用正确的时间x坐标)
set label 1 sprintf("%.2f", STATS_min) center at min_x, STATS_min point pt 7 ps 1 offset 0, -1.5
set label 2 sprintf("%.2f", STATS_max) center at max_x, STATS_max point pt 7 ps 1 offset 0, 1.5

# 重新绘制带标签的图表
replot

关键修改点:

  • 提前设置时间格式,确保timecolumn函数能正确解析数据中的时间字符串
  • 通过一次临时绘图,捕获最值对应的实际时间x值(而非行号)
  • 使用捕获到的min_x和max_x作为标签的x坐标,确保标签出现在图表的正确位置

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 19:42:09