1 #!/usr/bin/gnuplot -persist
5 # Version 4.6 patchlevel 6 last modified September 2014
6 # Build System: Linux x86_64
8 # Copyright (C) 1986-1993, 1998, 2004, 2007-2014
9 # Thomas Williams, Colin Kelley and many others
11 # gnuplot home: http://www.gnuplot.info
12 # faq, bugs, etc: type "help FAQ"
13 # immediate help: type "help" (plot window: hit 'h')
15 set title "Seasonal phenomenon, highlighted with a seasonal gradient in the background"
19 set key noreverse enhanced autotitles box linetype -1 linewidth 1.000
20 set key vert out bottom center
21 set key width 2 height 1
25 set timefmt "%Y-%m-%d"
27 set xtics out nomirror rotate by -45
29 set ylabel "y" norotate
30 set ytics out nomirror 1
32 # Define a color palette representing the "season temperature"
34 set palette maxcolors 4
35 set palette model HSV defined ( \
36 0 200/360. _saturation 1, \
37 1 100/360. _saturation 1, \
38 2 80/360. _saturation 1, \
39 3 20/360. _saturation 1, \
40 3 0/360. _saturation 1, \
41 3 360/360. _saturation 1, \
42 4 290/360. _saturation 1)
46 # Seasons order as in the northern hemiphere
47 set cbtics offset 0,+3 ( \
54 # Utility functions to deal with seasons
56 # When data is time, intervals are in seconds
57 one_year = 60 * 60 * 24 * 365.25
58 three_months = one_year / 4
60 # Argument is a month between 0 and 11
61 season(x) = ((int(x) + 1) % 12) / 3
63 # Argument is a season between 0 and 3.
65 # NOTE: when rotating modulo 12, increasing by 11 is the same as subtracting
66 # by 1, the increment is used here because gnuplot does not handle the modulo
67 # with negative numbers very well
68 first_month_of_season(x) = ((int(x) * 3) + 11) % 12
70 # Winter starts the previous year if the months are January (0) of February (1)
71 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")
73 # Dummy plot to gather some stats from the dataset
75 plot 'data.dat' using 1:2
77 xmin = start_of_season(GPVAL_DATA_X_MIN)
78 xmax = start_of_season(GPVAL_DATA_X_MAX + three_months)
82 set xrange [xmin:xmax]
83 set yrange [ymin:ymax]
85 # Calculate the x sampling rate for the '+' plot below.
86 # This way we draw only the strictly needed boxxys for the background.
88 # Divide by three_months in order to have intervals of three months each and
89 # round x_samples to the next multiple of 3 because the samples will be
90 # divided by 3 in the season() function to set the season color.
91 x_samples = ceil((xmax - xmin) / three_months / 3) * 3
92 set samples x_samples, 100
94 set xtics xmin,three_months
97 #set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0
98 #set output 'full_range_seasonal.png'
100 # Use the boxxyerrorbars style to draw the background choosing the color
101 # according to the season.
103 '+' using (0):(0):(start_of_season($1)):(start_of_season($1 + three_months)):(ymin):(ymax):(season(tm_mon($1))) with boxxy fc palette fs solid notitle, \
104 'data.dat' using 1:2 w l lc rgb "black" title "data"