Created
January 9, 2016 13:12
-
-
Save nipotan/11d1c8e50eed01490c23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use Chart::Gnuplot; | |
| use Time::Piece; | |
| use Time::Seconds; | |
| my @x = (); | |
| my @y = (); | |
| my $worst; | |
| my $best; | |
| while (my $line = <DATA>) { | |
| next if $line =~ /^\s*#.*$/; # comment | |
| chomp $line; | |
| my($date, $before, $after) = split /,/, $line; | |
| my($better, $worse) = | |
| $before <=> $after < 0 ? ($after, $before) : ($before, $after); | |
| $worst = $worst && $worst < $worse ? $worst : $worse; | |
| $best = $best && $best > $better ? $best : $better; | |
| push @x, $date; | |
| my $i = 0; | |
| for my $value ($before, $after, $before, $after) { | |
| $y[$i] ||= []; | |
| push @{$y[$i]}, $value; | |
| $i++; | |
| } | |
| } | |
| my $chart = Chart::Gnuplot->new( | |
| output => './stretch-chart.png', | |
| title => 'standing trunk flexion chart', | |
| imagesize => '0.7, 0.6', | |
| xrange => [ day_before($x[0]), day_after($x[-1]) ], | |
| yrange => [$worst - 5, $best + 5], | |
| timeaxis => 'x', | |
| xlabel => 'date', | |
| ylabel => 'depth', | |
| xtics => { | |
| labelfmt => '%m.%d', | |
| rotate => 270, | |
| font => 'Arial, 10', | |
| }, | |
| grid => { | |
| width => 1, | |
| type => 'dash', | |
| color => '#666666', | |
| }, | |
| ); | |
| my $dataset = Chart::Gnuplot::DataSet->new( | |
| style => 'candlesticks', | |
| timefmt => '%Y-%m-%d', | |
| grid => 'on', | |
| boxwidth => 10, | |
| xdata => \@x, | |
| ydata => \@y, | |
| title => 'effect of stretching', | |
| linetype => 1, | |
| color => 'blue', | |
| width => 2, | |
| ); | |
| $chart->plot2d($dataset); | |
| sub day_before { | |
| my $day = shift; | |
| my $before = Time::Piece->strptime($day, '%Y-%m-%d'); | |
| $before -= ONE_DAY; | |
| return $before->strftime('%Y-%m-%d'); | |
| } | |
| sub day_after { | |
| my $day = shift; | |
| my $after = Time::Piece->strptime($day, '%Y-%m-%d'); | |
| $after += ONE_DAY; | |
| return $after->strftime('%Y-%m-%d'); | |
| } | |
| __DATA__ | |
| 2010-10-12,-25.4,-13.0 | |
| 2010-10-18,-18.7,-6.8 | |
| 2010-10-19,-11.7,0.0 | |
| 2010-10-20,-5,+3.8 | |
| 2010-10-25,-1,+5.9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment