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 using a polar graph"
18 set timefmt "%Y-%m-%d"
21 # Dummy plot to gather some stats from the dataset
23 plot 'data.dat' using 1:2
25 xmin = GPVAL_DATA_X_MIN
26 xmax = GPVAL_DATA_X_MAX
27 ymin = GPVAL_DATA_Y_MIN
28 ymax = GPVAL_DATA_Y_MAX
32 set grid polar back lw 1
41 # XXX: offsets may need to be adjusted for a different data set
42 set offsets 0, 0.2, 0.1, 0.1
44 set rrange [ymin:ymax + 0.5]
46 # XXX: rtics may need to be adjusted for a different data set
49 year_min = tm_year(xmin)
50 year_max = tm_year(xmax)
52 set cbrange [year_min:year_max + 1]
54 # Generate colorbox labels programmatically
55 cblabels = 'set cbtics ( '
56 do for [i=year_min:year_max] {
57 cblabels = cblabels . '"' . i .'" ' . i .','
59 cblabels = cblabels . '"" ' . int(year_max + 1) .','
60 cblabels = cblabels . ' )'
63 # The value 12 works well with the default colorbox height
64 cbtics_offset = 12 / (year_max - year_min)
65 set cbtics offset 0,+cbtics_offset
67 set palette rgbformulae 31,-11,32
68 set palette maxcolors (year_max - year_min + 1)
70 # The radius below places the labels outside of the grid.
72 # XXX: It depends on the magnitude of the data values tho, and it may need to
73 # be adjusted for a different data set.
75 set_label(x, text) = sprintf("set label '%s' at (%f*cos(%f)), (%f*sin(%f)) center", text, r, x, r, x)
77 # Create labels for the months, apparently gnuplot does not allow to set ttics
78 month_angle(x) = x * 2 * pi / 12 + pi / 12
79 eval set_label(month_angle(0), "Jan")
80 eval set_label(month_angle(1), "Feb")
81 eval set_label(month_angle(2), "Mar")
82 eval set_label(month_angle(3), "Apr")
83 eval set_label(month_angle(4), "May")
84 eval set_label(month_angle(5), "Jun")
85 eval set_label(month_angle(6), "Jul")
86 eval set_label(month_angle(7), "Aug")
87 eval set_label(month_angle(8), "Sep")
88 eval set_label(month_angle(9), "Oct")
89 eval set_label(month_angle(10), "Nov")
90 eval set_label(month_angle(11), "Dec")
92 # Scale the data so that one year covers one circumference,
93 # this allows samples in the same time of the year to be at the same angles.
94 one_year = 60 * 60 * 24 * 365.25
95 scale_date_to_month_polar(x) = (int(x) % int(one_year)) / one_year * (2 * pi)
97 # With this hacky-ish wrap() function we loose some points when the data wraps
98 # around, but AFAIK this is unavoidable without preprocessing the data.
99 year_wrap(old, new) = tm_year(old) == tm_year(new) ? scale_date_to_month_polar(new) : NaN
101 if (GPVAL_VERSION < 5.0) \
102 tcol(x) = timecolumn(x); \
104 tcol(x) = timecolumn(x, "%Y-%m-%d")
107 #set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0
108 #set output 'modular_polar.png'
112 'data.dat' using (prev=saved, saved=tcol(1), year_wrap(prev, saved)):2:(tm_year(tcol(1))) with lines lc palette lw 1.5