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 montly 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 "month temperature".
33 # Angles taken from the link below, except for the first one as pure cyan was
35 # http://www.linuxtopia.org/online_books/graphics_tools/gimp_user_manual/images/glossary/colorcircle-en.png
37 set palette maxcolors 12
38 set palette model HSV defined ( \
39 0 220/360. _saturation 1, \
40 3 120/360. _saturation 1, \
41 5 60/360. _saturation 1, \
42 7 0/360. _saturation 1, \
43 7 360/360. _saturation 1, \
44 9 300/360. _saturation 1, \
45 11 240/360. _saturation 1)
48 set cbtics offset 0,+1 ( \
63 # Utility functions to deal with time
65 # When data is time, intervals are in seconds
66 one_year = 60 * 60 * 24 * 365.25
67 one_month = one_year / 12
68 three_months = one_year / 4
70 start_of_month(x) = strptime("%Y-%m-%d", "" . int(tm_year(x)) . "-". int(tm_mon(x) + 1) . "-01")
72 # strptime() seems to adjust the year automatically when passing a month > 12
73 start_of_next_month(x) = strptime("%Y-%m-%d", "" . int(tm_year(x)) . "-" . (int(tm_mon(x)) + 2) . "-01")
75 # Dummy plot to gather some stats from the dataset
77 plot 'data.dat' using 1:2
79 xmin = start_of_month(GPVAL_DATA_X_MIN)
80 xmax = start_of_next_month(GPVAL_DATA_X_MAX)
84 set xrange [xmin:xmax]
85 set yrange [ymin:ymax]
87 # Calculate the x sampling rate for the '+' plot below.
89 # The sample rate below is two times the strictly needed one because in this
90 # way the month spacing error is reduced: "set samples" assumes evenly
91 # distributed data, but starts of months are not, so it may happen that
92 # a month gets skipped or repeated.
94 # With this workaround most of the tiles of the background gradient will be
95 # drawn twice but there will be less chance of missing intervals because of
96 # accumulation of errors.
97 x_samples = int((xmax - xmin) / one_month) * 2
98 set samples x_samples, 100
100 set xtics three_months
103 #set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0
104 #set output 'full_range_monthly.png'
106 # Use the boxxyerrorbars style to draw the background choosing the color
107 # according to the month.
109 '+' using ($1):(0):(start_of_month($1)):(start_of_next_month($1)):(ymin):(ymax):(tm_mon($1)) with boxxy fc palette fs solid notitle, \
110 'data.dat' using 1:2 w l lc rgb "black" title "data"