From: Antonio Ospite Date: Mon, 22 Dec 2014 13:57:03 +0000 (+0100) Subject: Initial import X-Git-Url: https://git.ao2.it/experiments/gnuplot_seasonal_plot.git/commitdiff_plain/8b232e5a5380c6787fb46997873f2cc5116bfe19 Initial import --- 8b232e5a5380c6787fb46997873f2cc5116bfe19 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d67652f --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (C) 2015 Antonio Ospite + +This program is free software. It comes without any warranty, to +the extent permitted by applicable law. You can redistribute it +and/or modify it under the terms of the Do What The Fuck You Want +To Public License, Version 2, as published by Sam Hocevar. See +http://sam.zoy.org/wtfpl/COPYING for more details. diff --git a/base.gnuplot b/base.gnuplot new file mode 100755 index 0000000..5a7d5fb --- /dev/null +++ b/base.gnuplot @@ -0,0 +1,43 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Version 4.6 patchlevel 6 last modified September 2014 +# Build System: Linux x86_64 +# +# Copyright (C) 1986-1993, 1998, 2004, 2007-2014 +# Thomas Williams, Colin Kelley and many others +# +# gnuplot home: http://www.gnuplot.info +# faq, bugs, etc: type "help FAQ" +# immediate help: type "help" (plot window: hit 'h') + +set title "Basic data plot doesn't highlight the seasonal behaviour" + +set border 3 +set grid xtics back +set key noreverse enhanced autotitles box linetype -1 linewidth 1.000 +set key vert out bottom center +set key width 2 height 1 +set rmargin 8 + +set xdata time +set timefmt "%Y-%m-%d" +set format x "%b %y" +set xtics out nomirror rotate by -45 + +set ylabel "y" norotate +set ytics out nomirror 1 + +# When data is time, intervals are in seconds. +one_year = 60 * 60 * 24 * 365.25 +three_months = one_year / 4 + +set xtics three_months + +set terminal qt 0 +#set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0 +#set output 'base.png' + +plot \ + 'data.dat' using 1:2 w l lc rgb "black" title "data" diff --git a/data.dat b/data.dat new file mode 100644 index 0000000..cf744c8 --- /dev/null +++ b/data.dat @@ -0,0 +1,352 @@ +2009-01-20 17.87 +2009-01-21 17.78 +2009-01-24 17.66 +2009-01-25 17.61 +2009-01-26 17.65 +2009-01-27 17.61 +2009-01-28 17.61 +2009-01-29 17.56 +2009-01-30 17.62 +2009-01-31 17.57 +2009-02-01 17.61 +2009-02-23 17.76 +2009-02-28 17.68 +2009-03-21 17.69 +2009-03-22 17.65 +2009-03-23 17.71 +2009-03-27 17.69 +2009-03-28 17.68 +2009-04-08 17.66 +2009-04-20 17.75 +2009-04-22 17.72 +2009-04-23 17.70 +2009-04-24 17.76 +2009-05-07 17.63 +2009-05-09 17.68 +2009-05-10 17.66 +2009-05-12 17.69 +2009-05-13 17.64 +2009-05-14 17.64 +2009-05-15 17.59 +2009-05-18 17.65 +2009-05-19 17.60 +2009-05-20 17.58 +2009-05-21 17.51 +2009-05-22 17.53 +2009-05-23 17.48 +2009-05-25 17.48 +2009-05-26 17.49 +2009-05-27 17.46 +2009-05-29 17.52 +2009-06-02 17.44 +2009-06-03 17.43 +2009-06-08 17.38 +2009-06-14 17.34 +2009-06-19 17.31 +2009-06-23 17.29 +2009-06-25 17.24 +2009-06-30 17.29 +2009-07-02 17.26 +2009-07-06 17.22 +2009-07-07 17.26 +2009-07-09 17.25 +2009-07-11 17.25 +2009-07-12 17.28 +2009-07-13 17.21 +2009-07-14 17.19 +2009-07-15 17.20 +2009-07-17 17.22 +2009-07-18 17.17 +2009-07-20 17.12 +2009-07-21 17.10 +2009-07-22 17.15 +2009-07-27 17.15 +2009-07-30 17.18 +2009-07-31 17.14 +2009-08-02 17.20 +2009-08-03 17.22 +2009-08-05 17.16 +2009-08-12 17.17 +2009-08-19 17.18 +2009-09-05 17.20 +2009-09-06 17.15 +2009-09-08 17.19 +2009-09-09 17.19 +2009-09-13 17.17 +2009-09-15 17.17 +2009-09-24 17.19 +2009-09-25 17.17 +2009-09-26 17.22 +2009-10-03 17.22 +2009-10-06 17.23 +2009-10-24 17.35 +2009-11-12 17.45 +2010-01-26 17.73 +2010-02-01 17.69 +2010-02-28 17.77 +2010-03-03 17.81 +2010-04-05 17.67 +2010-04-08 17.76 +2010-04-09 17.75 +2010-04-11 17.68 +2010-04-12 17.63 +2010-04-13 17.57 +2010-04-15 17.60 +2010-04-16 17.60 +2010-04-17 17.67 +2010-04-20 17.64 +2010-04-21 17.65 +2010-04-22 17.61 +2010-04-26 17.66 +2010-05-01 17.63 +2010-05-03 17.60 +2010-05-05 17.55 +2010-05-06 17.58 +2010-05-08 17.48 +2010-05-09 17.53 +2010-05-10 17.55 +2010-05-12 17.55 +2010-05-13 17.52 +2010-05-15 17.51 +2010-05-16 17.50 +2010-05-17 17.44 +2010-05-19 17.42 +2010-05-20 17.46 +2010-05-25 17.51 +2010-05-26 17.48 +2010-05-30 17.49 +2010-05-31 17.48 +2010-06-02 17.46 +2010-06-04 17.44 +2010-06-05 17.48 +2010-06-06 17.42 +2010-06-09 17.46 +2010-06-10 17.49 +2010-06-11 17.44 +2010-06-12 17.40 +2010-06-13 17.44 +2010-06-16 17.43 +2010-06-17 17.43 +2010-06-21 17.42 +2010-06-23 17.36 +2010-06-29 17.38 +2010-07-02 17.36 +2010-07-03 17.39 +2010-07-06 17.39 +2010-07-09 17.44 +2010-07-10 17.45 +2010-07-12 17.39 +2010-07-14 17.41 +2010-07-15 17.37 +2010-07-19 17.39 +2010-07-22 17.32 +2010-07-23 17.34 +2010-07-26 17.35 +2010-07-27 17.36 +2010-07-29 17.42 +2010-07-31 17.39 +2010-08-07 17.35 +2010-08-09 17.27 +2010-08-10 17.26 +2010-08-11 17.35 +2010-08-19 17.31 +2010-08-20 17.29 +2010-08-25 17.35 +2010-08-30 17.36 +2010-09-06 17.34 +2010-09-07 17.36 +2010-09-10 17.35 +2010-09-18 17.37 +2010-09-24 17.47 +2010-10-04 17.56 +2010-10-05 17.54 +2010-10-15 17.60 +2010-10-20 17.65 +2010-10-27 17.64 +2010-11-01 17.61 +2010-11-03 17.62 +2010-11-07 17.68 +2010-11-09 17.74 +2010-11-12 17.69 +2010-11-13 17.75 +2010-11-22 17.80 +2010-12-04 17.76 +2010-12-18 17.86 +2010-12-23 17.91 +2011-01-02 17.88 +2011-01-09 17.96 +2011-01-17 17.96 +2011-01-28 17.84 +2011-01-31 17.91 +2011-02-01 17.89 +2011-02-10 17.90 +2011-02-15 17.96 +2011-02-19 17.97 +2011-02-22 17.93 +2011-02-28 17.91 +2011-03-03 17.95 +2011-03-15 18.05 +2011-03-18 17.94 +2011-03-19 17.93 +2011-03-22 17.91 +2011-03-23 17.92 +2011-03-25 17.90 +2011-03-26 17.89 +2011-03-27 17.90 +2011-03-30 17.90 +2011-03-31 17.86 +2011-04-01 17.84 +2011-04-06 17.90 +2011-04-07 17.86 +2011-04-08 17.84 +2011-04-09 17.86 +2011-04-11 17.89 +2011-04-13 17.85 +2011-04-18 17.76 +2011-04-26 17.77 +2011-04-28 17.88 +2011-04-30 17.85 +2011-05-05 17.81 +2011-05-11 17.84 +2011-05-17 17.80 +2011-05-22 17.84 +2011-05-26 17.82 +2011-05-30 17.74 +2011-05-31 17.74 +2011-06-02 17.76 +2011-06-03 17.74 +2011-06-06 17.75 +2011-06-07 17.78 +2011-06-10 17.80 +2011-06-12 17.74 +2011-06-17 17.77 +2011-06-20 17.77 +2011-06-28 17.81 +2011-07-12 17.81 +2011-07-13 17.79 +2011-07-17 17.74 +2011-07-18 17.76 +2011-07-20 17.74 +2011-08-01 17.86 +2011-08-03 17.78 +2011-08-12 17.70 +2011-08-14 17.76 +2011-08-15 17.70 +2011-08-28 17.81 +2011-09-05 17.77 +2011-09-09 17.79 +2011-09-21 17.81 +2011-09-22 17.78 +2011-09-24 17.81 +2011-09-27 17.77 +2011-10-01 17.79 +2011-10-02 17.76 +2011-10-03 17.80 +2011-10-15 17.81 +2011-10-28 17.92 +2011-11-17 17.94 +2011-12-11 18.03 +2012-01-04 18.21 +2012-01-12 18.15 +2012-01-13 18.17 +2012-01-26 18.20 +2012-02-02 18.20 +2012-02-19 18.30 +2012-03-04 18.30 +2012-03-14 18.15 +2012-03-15 18.13 +2012-03-17 18.17 +2012-03-20 18.19 +2012-03-21 18.15 +2012-03-23 18.22 +2012-03-25 18.12 +2012-03-26 18.07 +2012-03-28 18.14 +2012-04-03 18.07 +2012-04-04 18.05 +2012-04-05 18.13 +2012-04-07 18.09 +2012-04-08 17.96 +2012-04-10 18.10 +2012-04-12 18.03 +2012-04-16 18.04 +2012-04-18 18.04 +2012-04-19 18.03 +2012-04-23 18.03 +2012-04-27 17.99 +2012-05-02 17.90 +2012-05-04 17.88 +2012-05-06 17.85 +2012-05-09 17.84 +2012-05-12 17.83 +2012-05-14 17.77 +2012-05-16 17.82 +2012-05-20 17.77 +2012-05-21 17.72 +2012-05-23 17.70 +2012-05-28 17.69 +2012-05-30 17.68 +2012-05-31 17.65 +2012-06-02 17.65 +2012-06-03 17.65 +2012-06-04 17.63 +2012-06-06 17.65 +2012-06-07 17.69 +2012-06-13 17.77 +2012-06-15 17.70 +2012-06-17 17.63 +2012-06-18 17.65 +2012-06-19 17.64 +2012-06-20 17.65 +2012-06-21 17.62 +2012-06-25 17.57 +2012-06-26 17.57 +2012-06-27 17.61 +2012-06-30 17.57 +2012-07-01 17.54 +2012-07-02 17.54 +2012-07-03 17.57 +2012-07-04 17.56 +2012-07-06 17.50 +2012-07-07 17.51 +2012-07-10 17.57 +2012-07-11 17.52 +2012-07-13 17.59 +2012-07-16 17.53 +2012-07-17 17.62 +2012-07-23 17.61 +2012-07-26 17.58 +2012-07-27 17.55 +2012-08-01 17.55 +2012-08-04 17.52 +2012-08-05 17.53 +2012-08-06 17.58 +2012-08-10 17.52 +2012-08-15 17.53 +2012-08-17 17.50 +2012-08-26 17.42 +2012-08-28 17.46 +2012-08-30 17.52 +2012-09-06 17.56 +2012-09-07 17.52 +2012-09-10 17.52 +2012-09-13 17.55 +2012-09-14 17.55 +2012-09-15 17.54 +2012-09-22 17.57 +2012-09-24 17.59 +2012-09-29 17.62 +2012-10-04 17.70 +2012-10-10 17.67 +2012-10-24 17.81 +2012-11-01 17.85 +2012-11-05 17.93 +2012-11-07 18.00 +2012-11-15 18.02 +2012-11-22 18.04 +2012-11-26 18.10 +2012-12-02 18.18 +2012-12-08 18.20 +2012-12-17 18.35 +2012-12-21 18.27 +2012-12-29 18.36 diff --git a/full_range_monthly.gnuplot b/full_range_monthly.gnuplot new file mode 100755 index 0000000..98c6578 --- /dev/null +++ b/full_range_monthly.gnuplot @@ -0,0 +1,110 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Version 4.6 patchlevel 6 last modified September 2014 +# Build System: Linux x86_64 +# +# Copyright (C) 1986-1993, 1998, 2004, 2007-2014 +# Thomas Williams, Colin Kelley and many others +# +# gnuplot home: http://www.gnuplot.info +# faq, bugs, etc: type "help FAQ" +# immediate help: type "help" (plot window: hit 'h') + +set title "Seasonal phenomenon, highlighted with a montly gradient in the background" + +set border 3 +set grid xtics back +set key noreverse enhanced autotitles box linetype -1 linewidth 1.000 +set key vert out bottom center +set key width 2 height 1 +set rmargin 8 + +set xdata time +set timefmt "%Y-%m-%d" +set format x "%b %y" +set xtics out nomirror rotate by -45 + +set ylabel "y" norotate +set ytics out nomirror 1 + +# Define a color palette representing the "month temperature". +# Angles taken from the link below, except for the first one as pure cyan was +# too bright: +# http://www.linuxtopia.org/online_books/graphics_tools/gimp_user_manual/images/glossary/colorcircle-en.png +_saturation = .5 +set palette maxcolors 12 +set palette model HSV defined ( \ + 0 220/360. _saturation 1, \ + 3 120/360. _saturation 1, \ + 5 60/360. _saturation 1, \ + 7 0/360. _saturation 1, \ + 7 360/360. _saturation 1, \ + 9 300/360. _saturation 1, \ + 11 240/360. _saturation 1) + +set cbrange [0:12] +set cbtics offset 0,+1 ( \ + 'Jan' 0, \ + 'Feb' 1, \ + 'Mar' 2, \ + 'Apr' 3, \ + 'May' 4, \ + 'Jun' 5, \ + 'Jul' 6, \ + 'Aug' 7, \ + 'Sep' 8, \ + 'Oct' 9, \ + 'Nov' 10, \ + 'Dec' 11, \ + '' 12) + +# Utility functions to deal with time + +# When data is time, intervals are in seconds +one_year = 60 * 60 * 24 * 365.25 +one_month = one_year / 12 +three_months = one_year / 4 + +start_of_month(x) = strptime("%Y-%m-%d", "" . int(tm_year(x)) . "-". int(tm_mon(x) + 1) . "-01") + +# strptime() seems to adjust the year automatically when passing a month > 12 +start_of_next_month(x) = strptime("%Y-%m-%d", "" . int(tm_year(x)) . "-" . (int(tm_mon(x)) + 2) . "-01") + +# Dummy plot to gather some stats from the dataset +set terminal unknown +plot 'data.dat' using 1:2 + +xmin = start_of_month(GPVAL_DATA_X_MIN) +xmax = start_of_next_month(GPVAL_DATA_X_MAX) +ymin = GPVAL_Y_MIN +ymax = GPVAL_Y_MAX + +set xrange [xmin:xmax] +set yrange [ymin:ymax] + +# Calculate the x sampling rate for the '+' plot below. +# +# The sample rate below is two times the strictly needed one because in this +# way the month spacing error is reduced: "set samples" assumes evenly +# distributed data, but starts of months are not, so it may happen that +# a month gets skipped or repeated. +# +# With this workaround most of the tiles of the background gradient will be +# drawn twice but there will be less chance of missing intervals because of +# accumulation of errors. +x_samples = int((xmax - xmin) / one_month) * 2 +set samples x_samples, 100 + +set xtics three_months + +set terminal qt 0 +#set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0 +#set output 'full_range_monthly.png' + +# Use the boxxyerrorbars style to draw the background choosing the color +# according to the month. +plot \ + '+' using ($1):(0):(start_of_month($1)):(start_of_next_month($1)):(ymin):(ymax):(tm_mon($1)) with boxxy fc palette fs solid notitle, \ + 'data.dat' using 1:2 w l lc rgb "black" title "data" diff --git a/full_range_seasonal.gnuplot b/full_range_seasonal.gnuplot new file mode 100755 index 0000000..cfeb338 --- /dev/null +++ b/full_range_seasonal.gnuplot @@ -0,0 +1,104 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Version 4.6 patchlevel 6 last modified September 2014 +# Build System: Linux x86_64 +# +# Copyright (C) 1986-1993, 1998, 2004, 2007-2014 +# Thomas Williams, Colin Kelley and many others +# +# gnuplot home: http://www.gnuplot.info +# faq, bugs, etc: type "help FAQ" +# immediate help: type "help" (plot window: hit 'h') + +set title "Seasonal phenomenon, highlighted with a seasonal gradient in the background" + +set border 3 +set grid xtics back +set key noreverse enhanced autotitles box linetype -1 linewidth 1.000 +set key vert out bottom center +set key width 2 height 1 +set rmargin 8 + +set xdata time +set timefmt "%Y-%m-%d" +set format x "%b %y" +set xtics out nomirror rotate by -45 + +set ylabel "y" norotate +set ytics out nomirror 1 + +# Define a color palette representing the "season temperature" +_saturation = .2 +set palette maxcolors 4 +set palette model HSV defined ( \ + 0 200/360. _saturation 1, \ + 1 100/360. _saturation 1, \ + 2 80/360. _saturation 1, \ + 3 20/360. _saturation 1, \ + 3 0/360. _saturation 1, \ + 3 360/360. _saturation 1, \ + 4 290/360. _saturation 1) + +set cbrange [0:4] + +# Seasons order as in the northern hemiphere +set cbtics offset 0,+3 ( \ + 'Winter' 0, \ + 'Spring' 1, \ + 'Summer' 2, \ + 'Autumn' 3, \ + '' 4) + +# Utility functions to deal with seasons + +# When data is time, intervals are in seconds +one_year = 60 * 60 * 24 * 365.25 +three_months = one_year / 4 + +# Argument is a month between 0 and 11 +season(x) = ((int(x) + 1) % 12) / 3 + +# Argument is a season between 0 and 3. +# +# NOTE: when rotating modulo 12, increasing by 11 is the same as subtracting +# by 1, the increment is used here because gnuplot does not handle the modulo +# with negative numbers very well +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") + +# Dummy plot to gather some stats from the dataset +set terminal unknown +plot 'data.dat' using 1:2 + +xmin = start_of_season(GPVAL_DATA_X_MIN) +xmax = start_of_season(GPVAL_DATA_X_MAX + three_months) +ymin = GPVAL_Y_MIN +ymax = GPVAL_Y_MAX + +set xrange [xmin:xmax] +set yrange [ymin:ymax] + +# Calculate the x sampling rate for the '+' plot below. +# 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 +set samples x_samples, 100 + +set xtics xmin,three_months + +set terminal qt 0 +#set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0 +#set output 'full_range_seasonal.png' + +# Use the boxxyerrorbars style to draw the background choosing the color +# according to the season. +plot \ + '+' 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, \ + 'data.dat' using 1:2 w l lc rgb "black" title "data" diff --git a/modular_cartesian.gnuplot b/modular_cartesian.gnuplot new file mode 100755 index 0000000..07f7aeb --- /dev/null +++ b/modular_cartesian.gnuplot @@ -0,0 +1,95 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Version 4.6 patchlevel 6 last modified September 2014 +# Build System: Linux x86_64 +# +# Copyright (C) 1986-1993, 1998, 2004, 2007-2014 +# Thomas Williams, Colin Kelley and many others +# +# gnuplot home: http://www.gnuplot.info +# faq, bugs, etc: type "help FAQ" +# immediate help: type "help" (plot window: hit 'h') + +set title "Seasonal phenomenon, highlighted wrapping around each year" + +set border 3 +set grid xtics back +set nokey +set rmargin 8 + +set xdata time +set timefmt "%Y-%m-%d" +set format x "%s" +set xtics out nomirror rotate by -45 +set ytics out nomirror 1 + +# Dummy plot to gather some stats from the dataset +set terminal unknown +plot 'data.dat' using 1:2 + +xmin = GPVAL_DATA_X_MIN +xmax = GPVAL_DATA_X_MAX + +# Plot over 12 months +set xrange[0:12] +set xtics ( \ + 'Jan' 0, \ + 'Feb' 1, \ + 'Mar' 2, \ + 'Apr' 3, \ + 'May' 4, \ + 'Jun' 5, \ + 'Jul' 6, \ + 'Aug' 7, \ + 'Sep' 8, \ + 'Oct' 9, \ + 'Nov' 10, \ + 'Dec' 11, \ + '' 12) + +year_min = tm_year(xmin) +year_max = tm_year(xmax) + +set cbrange [year_min:year_max + 1] + +# Generate colorbox labels programmatically +cblabels = 'set cbtics ( ' +do for [i=year_min:year_max] { + cblabels = cblabels . '"' . i .'" ' . i .',' +} +cblabels = cblabels . '"" ' . (i + 1) .',' +cblabels = cblabels . ' )' +eval(cblabels) + +# The value 12 works well with the default colorbox height +cbtics_offset = 12 / (year_max - year_min) +set cbtics offset 0,+cbtics_offset + +set palette rgbformulae 31,-11,32 +set palette maxcolors (year_max - year_min + 1) + +# Scale the data so that one year covers the xrange of 12 months, +# this allows samples in the same time of the year to be at the abscissa. +one_year = 60 * 60 * 24 * 365.25 +scale_date_to_month(x) = (int(x) % int(one_year)) / one_year * 12 + +# With this hacky-ish wrap() function we loose some points when the data wraps +# around, but AFAIK this is unavoidable without preprocessing the data. +# +# Value wraps around if the year changes between 'new' and 'old'. +year_wrap(old, new) = tm_year(old) == tm_year(new) ? scale_date_to_month(new) : NaN + +if (GPVAL_VERSION < 5.0) \ + tcol(x) = timecolumn(x); \ +else \ + tcol(x) = timecolumn(x, "%Y-%m-%d") + +set terminal qt 0 +#set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0 +#set output 'modular_cartesian.png' + +saved = -1 +plot \ + 'data.dat' using (prev=saved, saved=tcol(1), year_wrap(prev, saved)):2:(tm_year(tcol(1))) with lines lc palette lw 1.5 diff --git a/modular_polar.gnuplot b/modular_polar.gnuplot new file mode 100755 index 0000000..4c00f2f --- /dev/null +++ b/modular_polar.gnuplot @@ -0,0 +1,112 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Version 4.6 patchlevel 6 last modified September 2014 +# Build System: Linux x86_64 +# +# Copyright (C) 1986-1993, 1998, 2004, 2007-2014 +# Thomas Williams, Colin Kelley and many others +# +# gnuplot home: http://www.gnuplot.info +# faq, bugs, etc: type "help FAQ" +# immediate help: type "help" (plot window: hit 'h') + +set title "Seasonal phenomenon, highlighted using a polar graph" + +set xdata time +set timefmt "%Y-%m-%d" +set format x "%s" + +# Dummy plot to gather some stats from the dataset +set terminal unknown +plot 'data.dat' using 1:2 + +xmin = GPVAL_DATA_X_MIN +xmax = GPVAL_DATA_X_MAX +ymin = GPVAL_DATA_Y_MIN +ymax = GPVAL_DATA_Y_MAX + +set polar +set border 0 +set grid polar back lw 1 +set nokey + +unset xtics +unset ytics +unset raxis + +set size square + +# XXX: offsets may need to be adjusted for a different data set +set offsets 0, 0.2, 0.1, 0.1 + +set rrange [ymin:ymax + 0.5] + +# XXX: rtics may need to be adjusted for a different data set +#set rtics ymin,1 + +year_min = tm_year(xmin) +year_max = tm_year(xmax) + +set cbrange [year_min:year_max + 1] + +# Generate colorbox labels programmatically +cblabels = 'set cbtics ( ' +do for [i=year_min:year_max] { + cblabels = cblabels . '"' . i .'" ' . i .',' +} +cblabels = cblabels . '"" ' . (i + 1) .',' +cblabels = cblabels . ' )' +eval(cblabels) + +# The value 12 works well with the default colorbox height +cbtics_offset = 12 / (year_max - year_min) +set cbtics offset 0,+cbtics_offset + +set palette rgbformulae 31,-11,32 +set palette maxcolors (year_max - year_min + 1) + +# The radius below places the labels outside of the grid. +# +# XXX: It depends on the magnitude of the data values tho, and it may need to +# be adjusted for a different data set. +r = 1.6 +set_label(x, text) = sprintf("set label '%s' at (%f*cos(%f)), (%f*sin(%f)) center", text, r, x, r, x) + +# Create labels for the months, apparently gnuplot does not allow to set ttics +month_angle(x) = x * 2 * pi / 12 + pi / 12 +eval set_label(month_angle(0), "Jan") +eval set_label(month_angle(1), "Feb") +eval set_label(month_angle(2), "Mar") +eval set_label(month_angle(3), "Apr") +eval set_label(month_angle(4), "May") +eval set_label(month_angle(5), "Jun") +eval set_label(month_angle(6), "Jul") +eval set_label(month_angle(7), "Aug") +eval set_label(month_angle(8), "Sep") +eval set_label(month_angle(9), "Oct") +eval set_label(month_angle(10), "Nov") +eval set_label(month_angle(11), "Dec") + +# Scale the data so that one year covers one circumference, +# this allows samples in the same time of the year to be at the same angles. +one_year = 60 * 60 * 24 * 365.25 +scale_date_to_month_polar(x) = (int(x) % int(one_year)) / one_year * (2 * pi) + +# With this hacky-ish wrap() function we loose some points when the data wraps +# around, but AFAIK this is unavoidable without preprocessing the data. +year_wrap(old, new) = tm_year(old) == tm_year(new) ? scale_date_to_month_polar(new) : NaN + +if (GPVAL_VERSION < 5.0) \ + tcol(x) = timecolumn(x); \ +else \ + tcol(x) = timecolumn(x, "%Y-%m-%d") + +set terminal qt 0 +#set terminal png notransparent nocrop truecolor rounded enhanced font "arial,8" fontscale 1.0 +#set output 'modular_polar.png' + +saved = -1 +plot \ + 'data.dat' using (prev=saved, saved=tcol(1), year_wrap(prev, saved)):2:(tm_year(tcol(1))) with lines lc palette lw 1.5