plotpipe: 1D data supported.

This commit is contained in:
Ole Tange 2020-10-26 20:01:14 +01:00
parent 4c03edadce
commit 28e9986059
2 changed files with 33 additions and 7 deletions

6
plotpipe/example6.csv Normal file
View file

@ -0,0 +1,6 @@
header1
3
5
7
1
2
1 header1
2 3
3 5
4 7
5 1
6 2

View file

@ -14,7 +14,7 @@ I<datagenerator> | B<plotpipe> [-H] [-0] [-C str] [-h] [-V]
=head1 DESCRIPTION =head1 DESCRIPTION
B<plotpipe> is a simple wrapper for GNUPlot to simply plot 1D and 2D-data. B<plotpipe> is a simple wrapper for Gnuplot to simply plot data.
The input is a CSV-file. Lines starting with '#' will be used as The input is a CSV-file. Lines starting with '#' will be used as
titles on the plot. titles on the plot.
@ -67,6 +67,10 @@ Show version
=head1 EXAMPLE =head1 EXAMPLE
Plot the points (1,100) .. (100,1):
paste <(seq 100 -1 1) | plotpipe
Plot the points (1,101) .. (100,200): Plot the points (1,101) .. (100,200):
paste <(seq 100) <(seq 101 200) | plotpipe paste <(seq 100) <(seq 101 200) | plotpipe
@ -295,6 +299,9 @@ if(@title) { chomp($title[$#title]); }
if(not defined $opt::colsep) { if(not defined $opt::colsep) {
$opt::colsep = find_sep(@csv); $opt::colsep = find_sep(@csv);
} }
if($opt::colsep eq "") {
$opt::colsep = "\001soMe valUE tHat dOes nOT eXisT\002";
}
# Autoguess header # Autoguess header
my @header; my @header;
@ -319,14 +326,27 @@ use File::Temp qw(tempfile);
$ENV{'TMPDIR'} ||= "/tmp"; $ENV{'TMPDIR'} ||= "/tmp";
my($filehandle,$filename) = my($filehandle,$filename) =
tempfile(DIR=>$ENV{'TMPDIR'}, TEMPLATE => 'plotXXXXX'); tempfile(DIR=>$ENV{'TMPDIR'}, TEMPLATE => 'plotXXXXX');
for(@csv) { my $ncols = split /$opt::colsep/, $csv[0];
if($ncols >= 2) {
# Column 1 = x-axis
for(@csv) {
chomp; chomp;
# print((join "\t", split /$opt::colsep/, $_),"\n");
print $filehandle ((join "\001", split /$opt::colsep/, $_),"\n"); print $filehandle ((join "\001", split /$opt::colsep/, $_),"\n");
}
} else {
# Column 1 = y-axis
my $t = 1;
# Convert 1 column to 2 column
for(@csv) {
chomp;
print $filehandle ((join "\001", $t++, $_),"\n");
}
# Plot 2 columns
unshift(@header,"");
$ncols = 2;
} }
# Generate the variant part of Gnuplot script # Generate the variant part of Gnuplot script
my $ncols = split /$opt::colsep/, $csv[0];
for(my $col = 2; $col <= $ncols; $col++) { for(my $col = 2; $col <= $ncols; $col++) {
my $legend; my $legend;
if($opt::header) { if($opt::header) {
@ -348,6 +368,6 @@ plot @plotscript
_EOS _EOS
open GNUPLOT,"|-", "gnuplot -p -e ".Q($plotscript) or die; open GNUPLOT,"|-", "gnuplot -p -e ".Q($plotscript) or die;
# print "gnuplot -p -e ".($plotscript); #print "gnuplot -p -e ".($plotscript);
close GNUPLOT; close GNUPLOT;
unlink $filename; unlink $filename;