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

Gnuplot技术问询:如何为双坐标轴设置不同的timefmt

Hey there! Let's work through how to set up dual axes with different time formatting in gnuplot for your Oulu sunrise/sunset plot. From your existing script, it looks like you're plotting times as seconds after midnight against 2018 dates, and you want a second axis that uses a different time format. Here's a step-by-step solution:

First: Clarify timefmt vs format

A quick critical distinction:

  • timefmt tells gnuplot how to parse input time data (e.g., reading 01-01 as January 1st)
  • format controls how the axis labels are displayed (e.g., showing 01-01 or Jan 1)

For dual axes, we’ll use both depending on whether we’re configuring input parsing or output display.

Example 1: Dual Y-Axes (Seconds vs. Human-Readable Time)

If you want one y-axis to show raw seconds after midnight, and a second y-axis to show HH:MM time (like 06:30 instead of 23400), here’s your updated script:

set terminal png size 1000,500
set output "dose.png"

# Primary X-axis (2018 Dates, MM-DD format)
set xlabel "2018"
set xdata time
set timefmt "%m-%d"  # Parses input dates as MM-DD
set xtics "1",2592000,"365" out
set format x "%m-%d"  # Displays X-labels as MM-DD

# Primary Y-axis (Seconds after midnight)
set label 1 'secs after midnight' at graph -0.08, graph 0.3 rotate
set ytics "0",3600,"86400" out
set yrange ["0":"86399"]

# Secondary Y-axis (Human-readable HH:MM time)
set y2tics  # Enable the secondary Y-axis
set y2range [0:86399]  # Match primary Y-range to keep data aligned
set format y2 "%H:%M"  # Display Y2 labels as hours:minutes
set y2label "Time of Day"  # Add a clear label for the second axis

set title "sunrise and sunset at Oulu"
set key off
datafile="./f.data"

# Plot with both axes: filled curve on primary Y, line on secondary Y
plot datafile using 1:2 w filledcurve x1 lc rgb "#88ccff", \
     datafile using 1:2 w lines lc rgb "#000000" axes x1y2

Example 2: Dual X-Axes (Different Date Formats)

If you instead want two X-axes (e.g., one as MM-DD and another as Julian day 1-365), configure separate time parsing for the X2 axis:

# Primary X-axis (MM-DD format)
set xdata time
set timefmt "%m-%d"
set xtics format "%m-%d"
set xlabel "Date (MM-DD)"

# Secondary X-axis (Julian Day format)
set x2data time
set x2timefmt "%j"  # Parses input as Julian day (1-365)
set x2tics format "%j"  # Displays X2 labels as Julian day
set x2label "Julian Day"

Key Tips

  • Use axes x1y2 or axes x2y1 in your plot command to specify which axis pair to use for each dataset.
  • Always match the ranges of dual axes (e.g., y2range = yrange) so your data lines up correctly across both axes.
  • Each axis can have its own timefmt rule—just make sure you enable xdata time or x2data time for the axis you’re configuring.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:13:14