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

如何用Gnuplot绘制基于年、儒略日、HHMM的时间-第5列数据图表?

Fixing Gnuplot Time Series Plot with Combined Year, Julian Day, and Time Columns

Let's walk through fixing your Gnuplot script to correctly plot the 5th column against the combined time from columns 2 (year), 3 (Julian day), and 4 (HHMM). Here are the key issues in your original code and how to fix them:

1. Data Separator Mismatch

Your input data uses commas as separators, but Gnuplot defaults to whitespace. First, tell Gnuplot to recognize commas as the delimiter:

set datafile separator ","

2. Incorrect X-Axis Data Selection

You're only using column 2 ($2) for the x-axis, but your time is a combination of three columns. We need to merge these into a single string that matches your timefmt specification. Use the sprintf function to format them into the "YYYY,DDD,HHMM" pattern your timefmt expects:

# Combine year, Julian day, and HHMM into one time string
(sprintf("%d,%d,%d", $2, $3, $4))

3. X-Range Format Mismatch

Your xrange uses MM/DD/YYYY format, which doesn't align with the %Y,%j,%H%M format you set. You need to define the x-range using the same pattern as timefmt. For example:

  • January 15, 2018 translates to Julian day 045 → "2018,045,0000"
  • August 2, 2018 translates to Julian day 214 → "2018,214,2359"

Update the xrange line to:

set xrange ["2018,045,0000":"2018,214,2359"]

Full Working Script

Putting it all together, here's the corrected script (I added an optional line to make x-axis labels more readable):

set datafile separator ","
set xdata time
set timefmt "%Y,%j,%H%M"
# Optional: Format x-axis to show human-readable dates/times
set format x "%Y-%m-%d\n%H:%M"
set xrange ["2018,045,0000":"2018,214,2359"]
set yrange [0:5]
plot 'du1piezometerslong050318.dat' using (sprintf("%d,%d,%d",$2,$3,$4)):5 title 'July time series' with lp lw 4 pt 7 ps 0.75

Quick Notes

  • Ensure Julian days in your data are 3-digit values (e.g., 045 instead of 45) so the %j specifier parses them correctly.
  • The set format x line is optional but turns raw Julian day/time values into easy-to-read dates and times on your plot.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:08:19