能否设置非起始于00:00:00.000的X轴网格?附gnuplot配置指令
Absolutely you can tweak your gnuplot configuration to make the X-axis grid start at a time other than 00:00:00.000—let’s adjust your existing setup to get this working smoothly.
Background
Your current config already sets up a time-based X-axis, so we just need to align the grid with either custom starting ticks or explicit grid positions. Here are two straightforward approaches:
Approach 1: Align Grid with Custom Starting X-Tics
This is the simplest method—since the grid defaults to align with your X-axis ticks, you just need to set your xtics to start at your desired time, and the grid will follow suit automatically.
Update your config like this:
# Keep your existing core settings set grid x layerdefault front set xtics nomirror set ytics nomirror set xdata time set timefmt "%H:%M:%S" set format x "%H:%M:%.3S" # Define your desired grid start time (example: 00:05:00.000) desired_start = "00:05:00.000" maxtime = "01:00:00.000" # Replace with your actual max time value # Optional: Adjust xrange to exclude the 00:00 to start time range set xrange [desired_start:maxtime] # Set xtics to start at your desired time, with your preferred increment set xtics start desired_start increment 300 # Increment = 300 seconds (5 minutes)
- The
set xtics startcommand tells gnuplot to begin generating ticks at your specified time. - Since
set grid xis enabled, grid lines will automatically align with these custom ticks, starting atdesired_startinstead of00:00:00.000.
Approach 2: Manually Specify Grid Positions
If you want grid lines independent of your X-axis ticks (e.g., ticks start at 00:00 but grid starts later), you can explicitly define where grid lines appear using set grid x at.
Use the strptime function to convert your desired time into gnuplot’s internal numeric time format, then define grid positions:
# Keep your existing core settings set grid x layerdefault front set xtics nomirror set ytics nomirror set xdata time set timefmt "%H:%M:%S" set format x "%H:%M:%.3S" set xrange ["00:00:00.000":maxtime] # Convert your desired grid start time to gnuplot's numeric time value grid_start = strptime("%H:%M:%S", "00:05:00") # Define grid lines starting at grid_start, every 5 minutes (300 seconds) set grid x at grid_start, grid_start+300, grid_start+600, grid_start+900 # Extend this list as needed for your time range
- This method gives you full control over exactly where grid lines are drawn, even if they don’t match up with your axis ticks.
Quick Tips
- Ensure your
desired_starttime matches the format specified intimefmt(in your case,%H:%M:%S—you can include.000sincestrptimewill ignore the decimal, or adjusttimefmtto"%H:%M:%S.%3S"for strict millisecond parsing). - If you leave
xrangestarting at00:00:00.000, the grid will still begin at your desired time, leaving the early time range without grid lines.
内容的提问来源于stack exchange,提问作者Mkn

