From bb49958d8d3c7812119af6b3328d64df158a2351 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Fri, 30 Nov 2018 15:44:45 +0100 Subject: [PATCH 1/1] full_range_seasonal.gnuplot: fix calculating number of seasons The samples on the x axis are used to draw boxes in the background, one box per season. If the samples represent less seasons than what can be filled in the xrange, there will be holes in the background. Fix calculating the number of samples/seasons. --- full_range_seasonal.gnuplot | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/full_range_seasonal.gnuplot b/full_range_seasonal.gnuplot index cfeb338..f92cf07 100755 --- a/full_range_seasonal.gnuplot +++ b/full_range_seasonal.gnuplot @@ -70,6 +70,12 @@ first_month_of_season(x) = ((int(x) * 3) + 11) % 12 # Winter starts the previous year if the months are January (0) of February (1) start_of_season(x) = strptime("%Y-%m-%d", "" . (int(tm_year(x)) - (int(tm_mon(x)) < 2)) . "-" . int(first_month_of_season(season(tm_mon(x))) + 1) . "-21") +# Calculate the difference between two dates. +months_between_dates(a, b) = int((tm_year(b) - tm_year(a)) * 12 + tm_mon(b) - tm_mon(a)) + +# One season is 3 months. +seasons_between_dates(a, b) = int(months_between_dates(a, b) / 3) + # Dummy plot to gather some stats from the dataset set terminal unknown plot 'data.dat' using 1:2 @@ -83,12 +89,9 @@ set xrange [xmin:xmax] set yrange [ymin:ymax] # Calculate the x sampling rate for the '+' plot below. +# Have one sample per season, the +1 is to include the season of xmax. # This way we draw only the strictly needed boxxys for the background. -# -# Divide by three_months in order to have intervals of three months each and -# round x_samples to the next multiple of 3 because the samples will be -# divided by 3 in the season() function to set the season color. -x_samples = ceil((xmax - xmin) / three_months / 3) * 3 +x_samples = seasons_between_dates(xmin, xmax) + 1 set samples x_samples, 100 set xtics xmin,three_months -- 2.1.4