如何用Gnuplot绘制基于年、儒略日、HHMM的时间-第5列数据图表?
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.,
045instead of45) so the%jspecifier parses them correctly. - The
set format xline is optional but turns raw Julian day/time values into easy-to-read dates and times on your plot.
内容的提问来源于stack exchange,提问作者Shi Mulenga

