plotpipe: --log axis.

This commit is contained in:
Ole Tange 2021-03-03 22:18:06 +01:00
parent 3b0b378249
commit 112ed47440

View file

@ -9,12 +9,12 @@ plotpipe - Plot CSV data from a pipe
=head1 SYNOPSIS
I<datagenerator> | B<plotpipe> [-n] [-H] [-0] [--logx] [--logy] [-C str] [-h] [-V]
I<datagenerator> | B<plotpipe> [-n] [-H] [-0] [--log axis] [-C str] [-h] [-V]
=head1 DESCRIPTION
B<plotpipe> is a simple wrapper for Gnuplot to simply plot data.
B<plotpipe> is a simple wrapper for Gnuplot to simply plotting data.
The input is a CSV-file. Lines starting with '#' will be used as
titles on the plot.
@ -48,11 +48,11 @@ B<--header>.
Show help.
=item B<--logx>
=item B<--log x>
=item B<--logy>
=item B<--log y>
=item B<--logxy>
=item B<--log xy>
Logarithmic X/Y/X&Y axis.
@ -139,7 +139,18 @@ input.csv:
4 9 16
8 27 64
cat input.csv | plotpipe --nox --logy
cat input.csv | plotpipe --nox --log y
=head1 EXAMPLE: XY-line plots
You are not limited to a simple graph, but can also do XY-line plots.
seq 0 0.001 6.29 |
perl -nE 'say sin($_*100)*0.3+0.5*cos($_*2),",",
sin($_*2)-cos($_*100)*0.3,",",
sin($_)+cos($_*99),",",
sin($_*3)-cos($_*101)' |
plotpipe
=head1 LIMITS
@ -149,7 +160,7 @@ B<plotpipe> is limited by Gnuplot.
=head1 AUTHOR
Copyright (C) 2019-2020 Ole Tange,
Copyright (C) 2019-2021 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.
@ -173,12 +184,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES
B<pipeplot> uses B<gnuplot>.
B<pipeplot> uses B<gnuplot> and B<perl>.
=head1 SEE ALSO
B<perl>, B<gnuplot>
B<gnuplot>, B<perl>
=cut
@ -193,9 +204,7 @@ sub options_hash() {
"version|V" => \$opt::version,
"colsep|col-sep|C=s" => \$opt::colsep,
"help|h" => \$opt::help,
"logx" => \$opt::logx,
"logy" => \$opt::logy,
"logxy" => \$opt::logxy,
"log=s" => \$opt::log,
"null|0" => \$opt::null,
"nox|n" => \$opt::nox,
"header|H" => \$opt::header,
@ -208,7 +217,7 @@ sub version() {
print join
("\n",
"$Global::progname $Global::version",
"Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software",
"Copyright (C) 2020-2021 Ole Tange, http://ole.tange.dk and Free Software",
"Foundation, Inc.",
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
"This is free software: you are free to change and redistribute it.",
@ -219,6 +228,19 @@ sub version() {
);
}
sub status(@) {
my @w = @_;
my $fh = $Global::status_fd || *STDERR;
print $fh map { ($_, "\n") } @w;
flush $fh;
}
sub error(@) {
my @w = @_;
my $prog = $Global::progname || "plotpipe";
status(map { ($prog.": Error: ". $_); } @w);
}
sub help() {
# Returns: N/A
print join
@ -231,7 +253,7 @@ sub help() {
'-0 Records separated by \0 instead of \n',
'-C str Columns separator',
'-V Show version',
'--logx/logy/logxy Log x/y/x&y',
'--log A Log axis A (x y xy)',
'-n No X value',
'-s num Smooth num Y-values',
"",
@ -341,9 +363,12 @@ sub find_sep(@) {
Getopt::Long::Configure("bundling","require_order");
my $retval = GetOptions(options_hash());
if(not GetOptions(options_hash())) {
exit(255);
}
$Global::progname = "plotpipe";
$Global::version = 20201222;
$Global::version = 20210222;
if($opt::version) { version(); exit 0; }
if($opt::help) { help(); exit 0; }
if($opt::null) { $/ = "\0"; }
@ -409,8 +434,7 @@ if($ncols >= 2 and not $opt::nox) {
if($opt::smooth) {
my (@sum,@new);
if($#tbl < $opt::smooth) {
print STDERR "plotpipe: --smooth must be lower than the ",
"number of rows (",1+$#tbl,")\n";
error("--smooth must be lower than the number of rows (".(1+$#tbl).")");
exit(255);
}
my $smooth = $opt::smooth-1;
@ -445,16 +469,23 @@ for(my $col = 2; $col <= $ncols; $col++) {
if($opt::header) {
$legend = qq( title "$header[$col-1]");
}
push @plotscript, qq("$filename" using 1:$col with lines $legend,);
push @legend, qq("$filename" using 1:$col with lines $legend,);
}
# Add --logx/--logy/--logxy to Gnuplot script
# Add --log axis to Gnuplot script
my @logscale;
if($opt::logx or $opt::logxy) {
push @logscale, "set logscale x 10;";
}
if($opt::logy or $opt::logxy) {
push @logscale, "set logscale y 10;";
if($opt::log) {
if($opt::log eq "x") {
push @logscale, "set logscale x 10;";
} elsif($opt::log eq "y") {
push @logscale, "set logscale y 10;";
} elsif($opt::log eq "xy" or $opt::log eq "yx") {
push @logscale, "set logscale x 10;";
push @logscale, "set logscale y 10;";
} else {
error("--log $opt::log is not supported. Only x y xy are supported");
exit(255);
}
}
# Make full Gnuplot script
@ -467,7 +498,7 @@ set xlabel "$header[0]";
set grid;
set key right center;
set datafile separator "\001";
plot @plotscript
plot @legend
_EOS
open GNUPLOT,"|-", "gnuplot -p -e ".Q($plotscript) or die;