From: Antonio Ospite Date: Fri, 30 Nov 2018 14:44:45 +0000 (+0100) Subject: full_range_seasonal.gnuplot: fix calculating number of seasons X-Git-Url: https://git.ao2.it/experiments/gnuplot_seasonal_plot.git/commitdiff_plain/bb49958d8d3c7812119af6b3328d64df158a2351?hp=d2f20bb5c7a6313c76580ff953a0abfd7ee1cf17 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. --- 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