D Collins
D Collins

Reputation: 85

gnuplot xtic labels mispositioning with dates

Normally don't have problem with setting x tics but this one's defying solution for me.

Plotting some values along a daily time series, so leading off with the commands

set xdata time  
set timefmt "%m/%d/%Y"  # the incoming dates are like 06/19/2016  
set format x "%b %Y"    # I want the tics to be like Jun 2016

I have an arrow as a marker in the plot

set arrow 1 from "10/15/2016", 0 to "10/15/2016", 4  

...so I have a vertical line exactly on Oct 15 2016.

But with the command for my xtics...

set xtics "10/15/2016", 2628000

...I should have xtics beginning on Oct 15 and occurring at roughly the 15th of each month. Problem is, the first xtic shows up about where Oct 1st is, not the 15th. Subsequently, the spacing is indeed about one month, but they're all near the first of each month, not the 15th.

The arrow is just to give me a visual marker on the date Oct 15, and its command uses the same format as the xtics command. After an hour of no luck with every configuration I can think of, it's time to go external for a fresh set of eyes.

Upvotes: 2

Views: 551

Answers (1)

ewcz
ewcz

Reputation: 13097

in addition to the comment to the original question, the reason for this behavior seems to be that the function setup_tics in src/axis.c of the Gnuplot source tree sets (line 862) for values of the step larger than 3600*24*28 the timelevel of the corresponding major axis tics to TIMELEVEL_MONTHS.

However, as the comment in function time_tic_just on line 1351 of src/axis.c suggests (and code below confirms), the tic position is in this case indeed rounded to the first day of the month:

/* skip it, I have not bothered with weekday so far */
if (level >= TIMELEVEL_MONTHS) {/* units of month */
if (tm.tm_mday > 25) {
    tm.tm_mon++;
    if (tm.tm_mon > 11) {
    tm.tm_year++;
    tm.tm_mon = 0;
    }
}
tm.tm_mday = 1;
}

Upvotes: 2

Related Questions