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 wrapping around each year"
23 set timefmt "%Y-%m-%d"
25 set xtics out nomirror rotate by -45
26 set ytics out nomirror 1
28 # Dummy plot to gather some stats from the dataset
30 plot 'data.dat' using 1:2
32 xmin = GPVAL_DATA_X_MIN
33 xmax = GPVAL_DATA_X_MAX
52 year_min = tm_year(xmin)
53 year_max = tm_year(xmax)
55 set cbrange [year_min:year_max + 1]
57 # Generate colorbox labels programmatically
58 cblabels = 'set cbtics ( '
59 do for [i=year_min:year_max] {
60 cblabels = cblabels . '"' . i .'" ' . i .','
62 cblabels = cblabels . '"" ' . (i + 1) .','
63 cblabels = cblabels . ' )'
66 # The value 12 works well with the default colorbox height
67 cbtics_offset = 12 / (year_max - year_min)
68 set cbtics offset 0,+cbtics_offset
70 set palette rgbformulae 31,-11,32
71 set palette maxcolors (year_max - year_min + 1)
73 # Scale the data so that one year covers the xrange of 12 months,
74 # this allows samples in the same time of the year to be at the abscissa.
75 one_year = 60 * 60 * 24 * 365.25
76 scale_date_to_month(x) = (int(x) % int(one_year)) / one_year * 12
78 # With this hacky-ish wrap() function we loose some points when the data wraps
79 # around, but AFAIK this is unavoidable without preprocessing the data.
81 # Value wraps around if the year changes between 'new' and 'old'.
82 year_wrap(old, new) = tm_year(old) == tm_year(new) ? scale_date_to_month(new) : NaN
84 if (GPVAL_VERSION < 5.0) \
85 tcol(x) = timecolumn(x); \
87 tcol(x) = timecolumn(x, "%Y-%m-%d")
90 #set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0
91 #set output 'modular_cartesian.png'
95 'data.dat' using (prev=saved, saved=tcol(1), year_wrap(prev, saved)):2:(tm_year(tcol(1))) with lines lc palette lw 1.5