#!/usr/bin/perl -w use strict; use TimeSeries; use Getopt::Long; use Pod::Usage; =head1 NAME tsplot - plot time series in column format =head1 SYNOPSIS tsplotv [--legend-position pos] [--output-format format ] [--stacked] [--style style] [--time_t] [--tsv] [file ...] =head1 DESCRIPTION This program expects time series data in column format, I.e., each line contains a timestamp and the values for each series, except the first one which contains the column headers, which are used for the legend. Columns are separated by any amount of whitespace unless the --tsv option is given which enables tab-separated columns. The default legend position is "top right", same as with gnuplot. Another frequently useful position (especially if you have lots of series) is "below. Note that positions which consist of several world (such as "top right" need to be passed to tsplotv as a single argument, so the space needs to be hidden from the shell by use of quotes or a backslash. The default output format is "png", the default style is "lines". See L for a description of possible legend positions, output formats, and styles. The --stacked option causes the time series to be stacked on top of each other. The --time_t option specifies that the timestamps are in seconds since the epoch. Otherwise they are parsed by add_timestring function (which in turn uses the parse_date function of the HTTP::Date module). =cut my $output_format ='png'; my $log_y =0; my $time_t =0; my $style = "lines"; my $tsv = 0; my $stacked = 0; GetOptions('output_format|output-format=s' => \$output_format, 'log_y|log-y' => \$log_y, 'time_t' => \$time_t, 'style:s' => \$style, 'tsv' => \$tsv, 'stacked' => \$stacked, ) or pod2usage(verbose => 0); my $sep = $tsv ? qr/\t/ : ' '; binmode STDOUT, ':raw'; my $ts = TimeSeries->new(output_format => $output_format); while (<>) { chomp; my @legend = split($sep); shift @legend; # first must be for timestamp $ts->legend(@legend); last; } while (<>) { chomp; my ($timestamp, @values) = split($sep); if ($time_t) { $ts->add($timestamp, @values); } else { $ts->add_timestring($timestamp, @values); } } $ts->log_y($log_y); $ts->style($style); $ts->stacked($stacked); my $g = $ts->plot(); print $g