Graphics-GnuplotIF-1.6/0000755000175000001440000000000011533773702014172 5ustar mehnerusersGraphics-GnuplotIF-1.6/t/0000755000175000001440000000000011533773702014435 5ustar mehnerusersGraphics-GnuplotIF-1.6/t/pod.t0000644000175000001440000000151610704165206015400 0ustar mehnerusers#!perl -T #=============================================================================== # # FILE: pod.t # # DESCRIPTION: Testing POD # # FILES: --- # BUGS: --- # NOTES: --- # AUTHOR: Dr.-Ing. Fritz Mehner (Mn), # COMPANY: Fachhochschule Südwestfalen, Iserlohn # VERSION: 1.0 # CREATED: 06.06.2007 19:51:15 CEST # REVISION: $Id: pod.t,v 1.2 2007/10/13 15:55:50 mehner Exp $ #=============================================================================== use strict; use warnings; use Test::More; eval "use Test::Pod 1.0"; plan skip_all => "Test::Pod 1.0 required for testing POD" if $@; my $login; eval { $login = $ENV{USER} }; plan skip_all => "Only the author needs to check the POD documentation." if ($@ || $login ne "mehner" ); all_pod_files_ok(); Graphics-GnuplotIF-1.6/t/GnuplotIF.t0000644000175000001440000003124511533421655016473 0ustar mehnerusers# #=============================================================================== # # FILE: GnuplotIF.t # # DESCRIPTION: Test cases for GnuplotIF.pm # Before `make install' is performed this script should be # run with `make test'. After `make install' it should work # as `perl GnuplotIF.t' # # FILES: --- # BUGS: --- # NOTES: --- # AUTHOR: Dr.-Ing. Fritz Mehner (Mn), # COMPANY: Fachhochschule Südwestfalen, Iserlohn # CREATED: 27.08.2006 13:39:57 CEST # REVISION: $Id: GnuplotIF.t,v 1.11 2008/06/11 08:04:21 mehner Exp $ #=============================================================================== use strict; use warnings; use Math::Trig; use Test::More tests => 7; # last test to print use Graphics::GnuplotIF qw(GnuplotIF); #--------------------------------------------------------------------------- # tests #--------------------------------------------------------------------------- ok ( test1() , 'run Graphics::GnuplotIF demo 1' ); ok ( test2() , 'run Graphics::GnuplotIF demo 2' ); ok ( test3() , 'run Graphics::GnuplotIF demo 3' ); ok ( test4() , 'run Graphics::GnuplotIF demo 4' ); ok ( test5() , 'run Graphics::GnuplotIF demo 5' ); ok ( test6() , 'run Graphics::GnuplotIF demo 6' ); ok ( test7() , 'run Graphics::GnuplotIF demo 7' ); #--------------------------------------------------------------------------- # test function 1 #--------------------------------------------------------------------------- sub test1 { if ( !$ENV{'DISPLAY'} ) { return 1; } # no display; skip this test my @x = ( -2, -1.50, -1, -0.50, 0, 0.50, 1, 1.50, 2 ); # x values my @y1 = ( 4, 2.25, 1, 0.25, 0, 0.25, 1, 2.25, 4 ); # function 1 my @y2 = ( 2, 0.25, -1, -1.75, -2, -1.75, -1, 0.25, 2 ); # function 2 my $wait = 3; my $plotnumber = 0; my $timeformat = '%d-%m-%y %H:%M:%S'; #--------------------------------------------------------------------------- # plot object 1 #--------------------------------------------------------------------------- my $plot1 = Graphics::GnuplotIF->new( title => 'line', style => 'points', plot_titles => ['function 1.1', 'function 1.2'], ); $plotnumber++; $plot1->gnuplot_cmd("set timestamp \"plot number ${plotnumber} / ${timeformat}\" bottom"); $plot1->gnuplot_plot_y( \@x ); # plot 9 points over 0..8 $plot1->gnuplot_pause($wait); # wait $plot1->gnuplot_set_title('parabola'); # new title $plot1->gnuplot_set_style('lines'); # new line style $plotnumber++; $plot1->gnuplot_cmd("set timestamp \"plot number ${plotnumber} / ${timeformat}\" bottom"); $plot1->gnuplot_plot_xy( \@x, \@y1, \@y2 ); # rewrite plot1 : y1, y2 over x $plot1->gnuplot_pause($wait); # Plot same data again, this time with all default settings. $plot1->gnuplot_reset(); $plotnumber++; $plot1->gnuplot_cmd("set timestamp \"plot number ${plotnumber} / ${timeformat}\" bottom"); $plot1->gnuplot_plot_xy( \@x, \@y1, \@y2 ); # rewrite plot1 : y1, y2 over x $plot1->gnuplot_pause($wait); # Plot same data again, again starting from default settings, # but with individual plotting styles applied per function my %y1 = ( 'y_values' => \@y1, 'style_spec' => 'lines lw 3' ); my %y2 = ( 'y_values' => \@y2, 'style_spec' => 'points pointtype 4 pointsize 5' ); $plotnumber++; $plot1->gnuplot_cmd("set timestamp \"plot number ${plotnumber} / ${timeformat}\" bottom"); $plot1->gnuplot_plot_xy_style( \@x, \%y1, \%y2 ); $plot1->gnuplot_pause($wait); #--------------------------------------------------------------------------- # plot object 2 #--------------------------------------------------------------------------- my $plot2 = Graphics::GnuplotIF->new; $plot2->gnuplot_set_xrange( 0, '2*pi' ); # set x range $plot2->gnuplot_set_yrange( -2, 2 ); # set y range $plot2->gnuplot_cmd('set grid'); # send a gnuplot command $plot2->gnuplot_plot_equation( # 3 equations in one plot 'y1(x) = sin(x)', 'y2(x) = cos(x)', 'y3(x) = sin(x)/x' ); $plot2->gnuplot_pause($wait); # wait $plot2->gnuplot_plot_equation( # rewrite plot 2 'y4(x) = 2*exp(-x)*sin(4*x)' ); $plot2->gnuplot_pause($wait); # wait return 1; } # ---------- end of subroutine test1 ---------- #--------------------------------------------------------------------------- # test function 2 : write a script file #--------------------------------------------------------------------------- sub test2 { if ( !$ENV{'DISPLAY'} ) { return 1; } # no display; skip this test my $wait = 4; my $scriptfilename = 't/test2.gnuplot'; my @x = ( 0, +1, +0.8, 0, -1, -0.8, 0, +1, +0.8, 0, -1, -0.8, 0 ); if ( -e $scriptfilename ) { unlink $scriptfilename; } my $plot = Graphics::GnuplotIF->new( title => 'function #2', style => 'lines', plot_titles => ['function 2'], scriptfile => $scriptfilename, ); $plot->gnuplot_set_yrange( -1.5, +1.5 ); # set y range $plot->gnuplot_cmd('set xzeroaxis'); $plot->gnuplot_plot_y( \@x )->gnuplot_pause($wait); # plot and wait $plot->gnuplot_plot_y( \@x ); foreach my $count ( 1 ... 30 ) { # wait for the plot file if ( -e $scriptfilename ) { my @args = ( 'gnuplot', $scriptfilename ); system(@args) == 0 or die "system @args failed: $!"; $plot->gnuplot_pause(4); return 1; } sleep 1; } return 0; } # ---------- end of subroutine test2 ---------- #--------------------------------------------------------------------------- # test function 3 : animation #--------------------------------------------------------------------------- sub test3 { if ( !$ENV{'DISPLAY'} ) { return 1; } # no display; skip this test my $steps = 10; my $intervall = 2 * pi; my $n; my $plot1 = Graphics::GnuplotIF->new( title => 'Fourier Series -- Square Wave', silent_pause => 0, ); $plot1->gnuplot_cmd('set grid'); # send a gnuplot command $plot1->gnuplot_cmd('set key off'); # send a gnuplot command $plot1->gnuplot_cmd('set timestamp bottom'); # send a gnuplot command $plot1->gnuplot_set_xrange( 0, $intervall ); # set x range my $fourier = q{}; foreach my $i ( 1 .. $steps ) { $n = 2 * $i - 1; $fourier .= " +sin($n*x)/$n"; $plot1->gnuplot_cmd("plot (4/pi)*($fourier)")->gnuplot_pause(.4); } return 1; } # ---------- end of subroutine test3 ---------- #--------------------------------------------------------------------------- # test function 4 : hardcopy #--------------------------------------------------------------------------- sub test4 { if ( !$ENV{'DISPLAY'} ) { return 1; } # no display; skip this test my @x = ( 0, +1, +1, 0, -1, -1, 0, +1, +1, 0, -1, -1, 0 ); # x values my @y1 = ( 4, 2.25, 1, 0.25, 0, 0.25, 1, 2.25, 4 ); # function 1 my $plot = Graphics::GnuplotIF->new( title => 'function #4', style => 'lines', ); $plot->gnuplot_set_yrange( -1.5, +1.5 ); # set y range $plot->gnuplot_cmd('set xzeroaxis'); $plot->gnuplot_plot_y( \@x ); $plot->gnuplot_hardcopy( 't/function4.gnuplot.ps', 'postscript', 'color' ); $plot->gnuplot_plot_y( \@x ); $plot->gnuplot_restore_terminal(); $plot->gnuplot_pause(4); return 1; } # ---------- end of subroutine test4 ---------- #--------------------------------------------------------------------------- # test function 5 : 3-D-plot #--------------------------------------------------------------------------- sub test5 { if ( !$ENV{'DISPLAY'} ) { return 1; } # no display; skip this test my $plot = Graphics::GnuplotIF->new( title => 'function #5', style => 'lines', ); $plot->gnuplot_set_title('x*y*sin(x)*sin(y)'); # new title $plot->gnuplot_set_plot_titles('surface 1'); my @array; foreach my $i ( 0 .. 64 ) { foreach my $j ( 0 .. 64 ) { $array[$i][$j] = $i * $j * sin( 0.2 * $i ) * sin( 0.2 * $j ); } } $plot->gnuplot_plot_3d( \@array )->gnuplot_pause(6); return 1; } # ---------- end of subroutine test5 ---------- #--------------------------------------------------------------------------- # test function 6 : #--------------------------------------------------------------------------- sub test6 { if ( !$ENV{'DISPLAY'} ) { return 1; } # no display; skip this test my $plot = GnuplotIF( # constructor; short form title => 'test 6', style => 'lines', objectname => '=polynomials=', ); $plot->gnuplot_cmd('set grid'); # send a gnuplot command $plot->gnuplot_cmd('set xzeroaxis linestyle 1'); # send a gnuplot command my $timeformat = '%d-%m-%y %H:%M:%S'; my @x; my @y; foreach my $n ( 1 ... 4 ) { my ( $id, $name ) = $plot->gnuplot_get_object_id(); my $plotnumber = $plot->gnuplot_get_plotnumber(); $plot->gnuplot_set_plot_titles("(x-1)**$n"); foreach my $i ( 0 ... 40 ) { $x[$i] = 0.1 * $i - 2.0; $y[$i] = $x[$i]**$n; } $plot->gnuplot_cmd( "set timestamp \"plot object ${id} / plot number ${plotnumber} / ${timeformat}\" bottom" ); $plot->gnuplot_cmd( "set timestamp \"plot number ${plotnumber} / %d/%m/%y %H:%M\"" ); $plot->gnuplot_plot_xy( \@x, \@y )->gnuplot_pause(.4); } return 1; } # ---------- end of subroutine test6 ---------- #--------------------------------------------------------------------------- # test function 7 #--------------------------------------------------------------------------- sub test7 { if ( !$ENV{'DISPLAY'} ) { return 1; } # no display; skip this test my @x1 = ( -2, -1.50, -1, -0.50, 0, 0.50, 1, 1.50, 2 ); # x values (1.set) my @y1 = ( 4, 2.25, 1, 0.25, 0, 0.25, 1, 2.25, 4 ); # y-values (1.set) my @x2 = ( -4, -3.50, -3, -2.50, -2, -1.50, -1, -0.50, 0 );# x values (2.set) my @y2 = ( 5, 3.25, 2, 1.25, 1, 1.25, 2, 3.25, 5 );# y-values (2.set) my @x3 = ( 0, 0.50, 1, 1.50, 2, 2.50, 3, 3.50, 4 ); # x values (3.set) my @y3 = ( 3, 1.25, 0, -0.75, -1, -0.75, 0, 1.25, 3 ); # y-values (3.set) my $wait = 3; my $plotnumber = 0; my $timeformat = '%d-%m-%y %H:%M:%S'; #--------------------------------------------------------------------------- # plot object 1 #--------------------------------------------------------------------------- my $plot1 = Graphics::GnuplotIF->new( title => 'x-y-plot(s) not sharing an x-axis', style => 'lines', plot_titles => ['function 1.1', 'function 1.2', 'function 1.3'], ); $plotnumber++; $plot1->gnuplot_cmd("set timestamp \"plot number ${plotnumber} / ${timeformat}\" bottom"); $plot1->gnuplot_plot_many( \@x1, \@y1 )->gnuplot_pause($wait); $plotnumber++; $plot1->gnuplot_cmd("set timestamp \"plot number ${plotnumber} / ${timeformat}\" bottom"); $plot1->gnuplot_plot_many( \@x1, \@y1, \@x2, \@y2 )->gnuplot_pause($wait); $plotnumber++; $plot1->gnuplot_cmd("set timestamp \"plot number ${plotnumber} / ${timeformat}\" bottom"); $plot1->gnuplot_plot_many( \@x1, \@y1, \@x2, \@y2, \@x3, \@y3 )->gnuplot_pause($wait); my %f1 = ( 'x_values' => \@x1, 'y_values' => \@y1, 'style_spec' => "lines lw 3" ); my %f2 = ( 'x_values' => \@x2, 'y_values' => \@y2, 'style_spec' => "points pointtype 4 pointsize 5" ); $plot1->gnuplot_plot_many_style( \%f1, \%f2 )->gnuplot_pause($wait); #--------------------------------------------------------------------------- # plot object 2 #--------------------------------------------------------------------------- my @x21 = ( -2, -1.50, -1, -0.50, 0, 0.50, 1, 1.50, 2 ); # 9 points my @y21 = ( 4, 2.25, 1, 0.25, 0, 0.25, 1, 2.25, 4 ); # function 1 my @x22 = ( -1.1, -0.1, 0.9, 1.9, 2.9); # 5 points my @y22 = ( 0.1, 0.2, 0.3, 0.4, 0.5); # function 2 my $plot2 = Graphics::GnuplotIF->new( title => "parabola", style => "lines" ); $plot2->gnuplot_plot_many( \@x21, \@y21, \@x22, \@y22 )->gnuplot_pause($wait); return 1; } # ---------- end of subroutine test7 ---------- Graphics-GnuplotIF-1.6/t/pod-coverage.t0000644000175000001440000000161710631730123017166 0ustar mehnerusers#!perl -T #=============================================================================== # # FILE: pod-coverage.t # # DESCRIPTION: testing POD coverage # # FILES: --- # BUGS: --- # NOTES: --- # AUTHOR: Dr.-Ing. Fritz Mehner (Mn), # COMPANY: Fachhochschule Südwestfalen, Iserlohn # VERSION: 1.0 # CREATED: 06.06.2007 19:51:15 CEST # REVISION: $Id: pod-coverage.t,v 1.1.1.1 2007/06/07 07:14:27 mehner Exp $ #=============================================================================== use strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; my $login; eval { $login = $ENV{USER} }; plan skip_all => "Only the author needs to check the POD documentation." if ($@ || $login ne "mehner" ); all_pod_coverage_ok(); Graphics-GnuplotIF-1.6/t/00.load.t0000644000175000001440000000136510631730123015750 0ustar mehnerusers# #=============================================================================== # # FILE: 00.load.t # # DESCRIPTION: module load test # # FILES: --- # BUGS: --- # NOTES: --- # AUTHOR: Dr.-Ing. Fritz Mehner (Mn), # COMPANY: Fachhochschule Südwestfalen, Iserlohn # VERSION: 1.0 # CREATED: 06.06.2007 19:51:15 CEST # REVISION: $Id: 00.load.t,v 1.1.1.1 2007/06/07 07:14:27 mehner Exp $ #=============================================================================== use strict; use warnings; use Test::More tests => 1; # last test to print BEGIN { use_ok( 'Graphics::GnuplotIF' ); } diag( "Testing GnuplotIF $Graphics::GnuplotIF::VERSION" ); Graphics-GnuplotIF-1.6/Build.PL0000644000175000001440000000071710631730123015457 0ustar mehnerusersuse strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Graphics::GnuplotIF', license => 'perl', dist_author => 'Dr.-Ing. Fritz Mehner ', dist_version_from => 'lib/Graphics/GnuplotIF.pm', requires => { 'Test::More' => 0, 'version' => 0, }, add_to_cleanup => [ 'Graphics-GnuplotIF-*' ], ); $builder->create_build_script(); Graphics-GnuplotIF-1.6/lib/0000755000175000001440000000000011533773702014740 5ustar mehnerusersGraphics-GnuplotIF-1.6/lib/Graphics/0000755000175000001440000000000011533773702016500 5ustar mehnerusersGraphics-GnuplotIF-1.6/lib/Graphics/GnuplotIF.pm0000644000175000001440000012644711533773322020721 0ustar mehnerusers# #=============================================================================== # # FILE: GnuplotIF.pm # # DESCRIPTION: A simple and easy to use Perl interface to gnuplot. # (see POD below) # FILES: --- # BUGS: --- # NOTES: --- # AUTHOR: Dr.-Ing. Fritz Mehner (Mn), # COMPANY: FH Südwestfalen, Iserlohn # VERSION: see $VERSION below # CREATED: 16.07.2005 13:43:11 CEST # REVISION: $Id: GnuplotIF.pm,v 1.16 2011/03/03 20:15:14 mehner Exp $ #=============================================================================== package Graphics::GnuplotIF; use strict; use warnings; use Carp; use IO::Handle; our $VERSION = '1.6'; # version number use base qw(Exporter); use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); # Symbols to be exported by default @EXPORT_OK = ( 'GnuplotIF' ); #--------------------------------------------------------------------------- # Code common to gnuplot_plot_xy and gnuplot_plot_y to allow user-specified # titles set by gnuplot_set_plot_titles. This code assumes the plot titles # were all set in the command to the literal text "", without any # surrounding quotes. This function replaces that text. #--------------------------------------------------------------------------- my $private_apply_plot_titles = sub { my ($self, $cmd_ref) = @_; my $default_plot_title = q{-}; # Title if user did not specify one if (defined $self->{plot_titles} ) { # Substitute each plot title sequentially with the user-supplied value for my $plot_title (@{$self->{plot_titles}}) { if ( !defined $plot_title ) { $plot_title = $default_plot_title; } ${$cmd_ref} =~ s/title /title "$plot_title"/; } } # Substitute any plot titles we did not already catch globally ${$cmd_ref} =~ s/title /title "$default_plot_title"/g; }; #--------------------------------------------------------------------------- # Code generates a file comment for a plot script. #--------------------------------------------------------------------------- my $private_plot_script_header = sub { my ( $self ) = @_; my $localtime = scalar localtime; my $comment; ($comment = <<"END") =~ s/^\s+//gm; # # This file is a GNUPLOT plot script. # It was generated automatically by '${0}' # using the Graphics::GnuplotIF extension to perl. # Creation time : ${localtime} # END $self->gnuplot_cmd( $comment ); return; }; #--------------------------------------------------------------------------- # warn if there is no graphic display #--------------------------------------------------------------------------- if ( ! $ENV{'DISPLAY'} ) { warn "Graphics::GnuplotIF : cannot find environment variable DISPLAY \n" } #=== FUNCTION ================================================================ # NAME: new # DESCRIPTION: constructor # PARAMETER 1: anonymous hash containing some plot parameter (defaults shown): # style => "lines" # title => "", # xlabel => "", # ylabel => "", # xrange => [], # yrange => [], # scriptfile => "", # persist => 0, # objectname => "", # RETURNS: object reference #=============================================================================== { my $object_number = 0; # number of objects created sub new { my ( $class, %args ) = @_; my $self = { style => 'lines', title => q{}, xlabel => q{}, ylabel => q{}, xrange => [], yrange => [], plot_titles => [], scriptfile => q{}, persist => 0, objectname => q{}, silent_pause => 1, plot_also => 0, %args, __pausetime => -1, __pausemess => q{}, __objectnumber => ++$object_number, __plotnumber => 1, __error_log => q{}, __iohandle_pipe => undef, __iohandle_file => undef, }; bless $self, $class ; # let plot windows survive after gnuplot exits my $persist = q{}; if ( $self->{persist} == 1 ) { $persist = '-persist'; } $self->{__error_log} = ".gnuplot.${$}.${object_number}.stderr.log"; #------------------------------------------------------------------------------- # open pipe #------------------------------------------------------------------------------- if ( $self->{scriptfile} eq q{} || ( $self->{scriptfile} ne q{} && $self->{plot_also} != 0 ) ) { open $self->{__iohandle_pipe}, '|- ', "gnuplot ${persist} 2> $self->{__error_log}" or die "\n$0 : failed to open pipe to \"gnuplot\" : $!\n"; $self->{__iohandle_pipe}->autoflush(1); } #------------------------------------------------------------------------------- # open script file #------------------------------------------------------------------------------- if ( $self->{scriptfile} ne q{} ) { open $self->{__iohandle_file}, '>', $self->{scriptfile} or die "\n$0 : failed to open file \"$self->{scriptfile}\" : $!\n"; } $self->$private_plot_script_header(); $self->gnuplot_set_style ( $self->{style } ); $self->gnuplot_set_title ( $self->{title } ); $self->gnuplot_set_xlabel( $self->{xlabel} ); $self->gnuplot_set_ylabel( $self->{ylabel} ); $self->gnuplot_set_xrange( @{$self->{xrange}} ); $self->gnuplot_set_yrange( @{$self->{yrange}} ); return $self; } # ---------- end of subroutine new ---------- } #=== CLASS METHOD ============================================================ # NAME: GnuplotIF # PURPOSE: constructor - short form # PARAMETERS: see new #=============================================================================== sub GnuplotIF { my @args = @_; return __PACKAGE__->new(@args); } # ---------- end of subroutine GnuplotIF ---------- #=== CLASS METHOD ============================================================ # NAME: DESTROY # PURPOSE: destructor - close pipe or file # PARAMETERS: --- #=============================================================================== sub DESTROY { my $self = shift; #--------------------------------------------------------------------------- # close pipe to gnuplot / close the script file #--------------------------------------------------------------------------- if ( defined $self->{__iohandle_pipe} && !close $self->{__iohandle_pipe} ) { print { *STDERR } "Graphics::GnuplotIF (object $self->{__objectnumber}): " ."problem closing communication to gnuplot\n"; } if ( defined $self->{__iohandle_file} && !close $self->{__iohandle_file} ) { print { *STDERR } "Graphics::GnuplotIF (object $self->{__objectnumber}): " ."problem closing file $self->{scriptfile}\n"; } #--------------------------------------------------------------------------- # remove empty error logfiles, if any #--------------------------------------------------------------------------- my @stat = stat $self->{__error_log}; if ( defined $stat[7] && $stat[7]==0 ) { unlink $self->{__error_log} or croak "Couldn't unlink $self->{__error_log}: $!" } return; } # ---------- end of subroutine DESTROY ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_set_style # PURPOSE: Sets one of the allowed line styles in a plot command. # PARAMETERS: plotstyle (string) # RETURNS: --- # SEE ALSO: new() #=============================================================================== { my %linestyles = # allowed line styles ( boxes => q{}, dots => q{}, filledcurves=> q{}, fsteps => q{}, histeps => q{}, impulses => q{}, lines => q{}, linespoints => q{}, points => q{}, steps => q{}, ); sub gnuplot_set_style { my $self = shift; my $style = shift; if ( defined $style && exists $linestyles{$style} ) { $self->{style} = $style; } return; } # ---------- end of subroutine gnuplot_set_style ---------- } #=== CLASS METHOD ============================================================ # NAME: gnuplot_plot_y # PURPOSE: Plot one or more arrays over 0, 1, 2, 3, ... # PARAMETERS: array reference(s) # RETURNS: --- #=============================================================================== sub gnuplot_plot_y { my ( $self, @yref ) = @_; my $parnr = 0; my $cmd = " '-' with $self->{style} title ,\\\n" x (scalar @yref); $cmd =~ s/,\\$//s; $self->$private_apply_plot_titles(\$cmd); # Honor gnuplot_set_plot_titles return $self if $cmd eq q{}; $self->gnuplot_cmd( "plot \\\n$cmd\n" ); foreach my $item ( @yref ) { $parnr++; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_y : $parnr. " ."argument not an array reference\n" if ref($item) ne 'ARRAY'; $self->gnuplot_cmd( join( "\n", @{$item}), 'e' ); } # ----- end foreach ----- $self->{__plotnumber}++; return $self; } # ---------- end of subroutine gnuplot_plot_y ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_plot_xy # PURPOSE: x-y-plot(s) # PARAMETERS: 1. array reference : x-values # 2. array reference : y-values # ... # RETURNS: --- # DESCRIPTION: Takes two or more array references. The first array is assumed # to contain the x-values for the following function values. #=============================================================================== sub gnuplot_plot_xy { my ( $self, $xref, @yref ) = @_; my $parnr = 1; my $cmd = " '-' using 1:2 with $self->{style} title ,\\\n" x (scalar @yref); $cmd =~ s/,\\\n$//s; $self->$private_apply_plot_titles(\$cmd); # Honor gnuplot_set_plot_titles return $self if $cmd eq q{}; $self->gnuplot_cmd( "plot \\\n$cmd\n" ); die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_xy : $parnr. " ."argument not an array reference\n" if ref($xref) ne 'ARRAY'; foreach my $j ( 0..$#yref ) { $parnr++; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_xy - " ."$parnr. argument not an array reference\n" if ref($yref[$j]) ne 'ARRAY'; # there may be lesser y-values than x-values my $min = $#{$xref} < $#{$yref[$j]} ? $#{$xref} : $#{$yref[$j]}; foreach my $i ( 0..$min ) { $self->gnuplot_cmd( "$$xref[$i] $yref[$j]->[$i]" ); } $self->gnuplot_cmd( 'e' ); } $self->{__plotnumber}++; return $self; } # ---------- end of subroutine gnuplot_plot_xy ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_plot_many # PURPOSE: x-y-plot(s) not sharing an x-axis # PARAMETERS: 1. array reference1 : x-values # 2. array reference1 : y-values # (3. array reference2 : x-values) # (4. array reference2 : y-values) # ... # RETURNS: --- # DESCRIPTION: Takes pairs of array references. The first array in each pair # is assumed to contain the x-values and the second pair is # assumed to contain y-values #=============================================================================== sub gnuplot_plot_many { my ( $self, @array_refs ) = @_; my $parnr = 0; my $cmd = " '-' using 1:2 with $self->{style} title ,\\\n" x ( ( scalar @array_refs ) / 2 ); $cmd =~ s/,\\\n$//s; $self->$private_apply_plot_titles( \$cmd ); # Honor gnuplot_set_plot_titles return $self if $cmd eq q{}; $self->gnuplot_cmd("plot \\\n$cmd\n"); while (@array_refs) { my $xxr = shift @array_refs; $parnr++; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_many - " . "$parnr. argument not an array reference\n" if ref($xxr) ne 'ARRAY'; my $yyr = shift @array_refs; $parnr++; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_many - " . "$parnr. argument not an array reference\n" if ref($yyr) ne 'ARRAY'; # there may be fewer y-values than x-values my $min = $#{$xxr} < $#{$yyr} ? $#{$xxr} : $#{$yyr}; foreach my $i ( 0 .. $min ) { $self->gnuplot_cmd("$$xxr[$i] $$yyr[$i]"); } $self->gnuplot_cmd('e'); } $self->{__plotnumber}++; return $self; } # ---------- end of subroutine gnuplot_plot_many ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_plot_xy_style # PURPOSE: x-y-plot(s) with each graph using individual settings # PARAMETERS: 1. array reference : x-values # 2. hash reference : (y-values, y-style) # ... # RETURNS: --- # DESCRIPTION: Takes one array reference and one or more hash references. # The first array is assumed to contain the x-values for the # following function values. The following hashes are assumed # to contain pairs of values and settings. #=============================================================================== sub gnuplot_plot_xy_style { my ( $self, $xref, @yref ) = @_; my $parnr = 1; my ( $cmd, @cmd ); foreach my $j ( 0..$#yref ) { die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_xy_style - " .($parnr + $j + 1).". argument not a suitable hash reference\n" if ! (ref($yref[$j]) eq 'HASH' && exists $yref[$j]->{'style_spec'} && exists $yref[$j]->{'y_values'}); push @cmd, " '-' using 1:2 with $yref[$j]->{'style_spec'} title "; } $cmd = join ", \\\n", @cmd; $self->$private_apply_plot_titles(\$cmd); # Honor gnuplot_set_plot_titles return $self if $cmd eq q{}; $self->gnuplot_cmd( "plot \\\n$cmd" ); die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_xy_style : $parnr. " ."argument not an array reference\n" if ref($xref) ne 'ARRAY'; foreach my $j ( 0..$#yref ) { $parnr++; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_xy_style - " ."$parnr. argument is missing an array reference\n" if ref($yref[$j]->{'y_values'}) ne 'ARRAY'; # there may be lesser y-values than x-values my $min = $#{$xref} < $#{$yref[$j]->{'y_values'}} ? $#{$xref} : $#{$yref[$j]->{'y_values'}}; foreach my $i ( 0..$min ) { $self->gnuplot_cmd( "$$xref[$i] $yref[$j]->{'y_values'}->[$i]" ); } $self->gnuplot_cmd( 'e' ); } $self->{__plotnumber}++; return $self; } # ---------- end of subroutine gnuplot_plot_xy_style ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_plot_many_style # PURPOSE: x-y-plot(s) not sharing an x-axis using individual settings # PARAMETERS: 1. hash reference1 : (x-values, y-values, y-style) # 2. hash reference2 : (x-values, y-values, y-style) # ... # RETURNS: --- # DESCRIPTION: Takes array of hash references. The hashes are assumed # to contain x- and y-values and settings. #=============================================================================== sub gnuplot_plot_many_style { my ( $self, @hash_refs ) = @_; my $parnr = 0; my ( $cmd, @cmd ); foreach my $rh (@hash_refs) { $parnr++; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_many_style - " .($parnr).". argument not a suitable hash reference\n" if ! ( ref($rh) eq 'HASH' && exists $rh->{'style_spec'} && exists $rh->{'x_values'} && exists $rh->{'y_values'} ); my $style = $rh->{'style_spec'}; push @cmd, " '-' using 1:2 with $style title "; }; $cmd = join ", \\\n", @cmd; $self->$private_apply_plot_titles(\$cmd); # Honor gnuplot_set_plot_titles return $self if $cmd eq q{}; $self->gnuplot_cmd( "plot \\\n$cmd\n" ); $parnr = 0; foreach my $rh (@hash_refs) { my $xref = $rh->{'x_values'}; my $yref = $rh->{'y_values'}; $parnr++; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_many_style - " ."$parnr. 'x_values' argument not an array reference\n" if ref($xref) ne 'ARRAY'; die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_many_style - " ."$parnr. 'y_values' argument not an array reference\n" if ref($yref) ne 'ARRAY'; # there may be fewer y-values than x-values my $min = $#{$xref} < $#{$yref} ? $#{$xref} : $#{$yref}; foreach my $i ( 0..$min ) { $self->gnuplot_cmd( "$$xref[$i] $$yref[$i]" ); } $self->gnuplot_cmd( 'e' ); } $self->{__plotnumber}++; return $self; } # ---------- end of subroutine gnuplot_plot_many_style ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_plot_equation # PURPOSE: Plot one or more functions described by strings. # PARAMETERS: strings describing functions # RETURNS: --- #=============================================================================== sub gnuplot_plot_equation { my ( $self, @equations ) = @_; my $leftside; my @leftside; foreach my $equ ( @equations ) { $self->gnuplot_cmd( "$equ" ); ( $leftside ) = split /=/, $equ; push @leftside, $leftside; } # ----- end foreach ----- @leftside = map {$_." with $self->{style}"} @leftside; $leftside = join ', ', @leftside; return $self if $leftside eq q{}; $self->gnuplot_cmd( "plot $leftside" ); $self->{__plotnumber}++; return $self; } # ---------- end of subroutine gnuplot_plot_equation ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_plot_3d # PURPOSE: Draw 3-d plots. # PARAMETERS: Reference to a 2-D-matrix containing the z-values. # RETURNS: --- #=============================================================================== sub gnuplot_plot_3d { my ( $self, $arrayref ) = @_; my $parnr = 0; my $cmd = " '-' matrix with $self->{style} title ," ; $cmd =~ s/,$//; $self->$private_apply_plot_titles(\$cmd); # Honor gnuplot_set_plot_titles return $self if $cmd eq q{}; $self->gnuplot_cmd( "splot $cmd" ); die "Graphics::GnuplotIF (object $self->{__objectnumber}): gnuplot_plot_3d : " ."argument not an array reference\n" if ref($arrayref) ne 'ARRAY'; foreach my $i ( @{$arrayref} ) { $self->gnuplot_cmd( join q{ }, @{$i} ) ; } $self->gnuplot_cmd( "\ne" ); $self->{__plotnumber}++; return $self; } # ---------- end of subroutine gnuplot_plot_3d ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_pause # PURPOSE: Wait a specified amount of time. # PARAMETERS: 1. parameter (optional): time value (seconds): # -1 do not wait # 0 wait for a carriage return # >0 wait the specified number of seconds # 2. parameter (optional): text # message to display # RETURNS: --- #=============================================================================== sub gnuplot_pause { my ( $self, $pause, $message ) = @_; $self->{__pausetime} = 0; # default: wait for a carriage return if ( defined $pause && $pause =~ m/^[+-]?(\d+|\d+\.\d*|\d*\.\d+)$/x ) { $self->{__pausetime} = $pause; } if ( defined $message && $message ne q{} ) { $self->{__pausemess} = "\"$message\""; } my $msg0 = "Graphics::GnuplotIF (object $self->{__objectnumber}): $self->{__pausemess} -- "; my $msg1 = "hit RETURN to continue \n"; my $msg2 = "wait $self->{__pausetime} second(s) \n"; if ( $self->{__pausetime} == 0 ) { print "$msg0$msg1"; my $dummy = <>; # hit RETURN to go on } elsif ( $self->{__pausetime} < 0 ) { $self->gnuplot_cmd("\n"); } else { if ( $self->{silent_pause} == 1 ) { print "$msg0$msg2"; } $self->gnuplot_cmd( "pause $self->{__pausetime}" ); } return $self; } # ---------- end of subroutine gnuplot_pause ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_cmd # PURPOSE: Pass on one or more Gnuplot commands. # PARAMETERS: string(s) # RETURNS: --- #=============================================================================== sub gnuplot_cmd { my ($self, @commands) = @_; @commands = map {$_."\n"} @commands; if ( defined $self->{__iohandle_pipe} ) { print { $self->{__iohandle_pipe} } @commands or croak "Couldn't write to pipe: $!"; } if ( defined $self->{__iohandle_file} ) { print { $self->{__iohandle_file} } @commands or croak "Couldn't write to file $!"; } return $self; } # ---------- end of subroutine gnuplot_cmd ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_hardcopy # PURPOSE: Write a plot into a file. # PARAMETERS: 1. file name # 2. gnuplot terminal type # 3. terminal settings (optional) # RETURNS: --- #=============================================================================== sub gnuplot_hardcopy { my ($self, $filename, $terminal, @keywords) = @_; # remember the current terminal including its settings $self->gnuplot_cmd( 'set terminal push' ); my $set_terminal = "set terminal $terminal @keywords\n"; my $set_output = "set output \"$filename\"\n"; $self->gnuplot_cmd( $set_terminal, $set_output ); return $self; } # ---------- end of subroutine gnuplot_hardcopy ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_restore_terminal # PURPOSE: Restore the terminal settings before the last hardcopy. # PARAMETERS: --- # RETURNS: --- #=============================================================================== sub gnuplot_restore_terminal { my ($self) = @_; $self->gnuplot_cmd( 'set output', 'set terminal pop' ); return $self; } # ---------- end of subroutine gnuplot_restore_terminal ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_set_plot_titles # PURPOSE: Sets the list of titles used in the key. # PARAMETERS: array of titles # RETURNS: --- #=============================================================================== sub gnuplot_set_plot_titles { my ( $self, @user_plot_titles ) = @_; my @plot_titles = @user_plot_titles; $self->{plot_titles} = \@plot_titles; return $self; } #=== CLASS METHOD ============================================================ # NAME: gnuplot_reset # PURPOSE: Set all options set with the set command to their # gnuplot default values. # PARAMETERS: --- # RETURNS: --- #=============================================================================== sub gnuplot_reset { my ($self) = @_; $self->{plot_titles} = undef; $self->gnuplot_cmd( 'reset' ); return $self; } # ---------- end of subroutine gnuplot_reset ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_set_title # PURPOSE: Sets the plot title. # PARAMETERS: title (string) # RETURNS: --- #=============================================================================== sub gnuplot_set_title { my ( $self, $title ) = @_; if ( defined $title ) { $self->gnuplot_cmd( "set title '$title'" ); }; return $self; } # ---------- end of subroutine gnuplot_set_title ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_set_xlabel # PURPOSE: Sets the x axis label. # PARAMETERS: string # RETURNS: --- #=============================================================================== sub gnuplot_set_xlabel { my ( $self, $xlabel ) = @_; if ( defined $xlabel ) { $self->gnuplot_cmd( "set xlabel \"$xlabel\"" ); }; return $self; } # ---------- end of subroutine gnuplot_set_xlabel ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_set_ylabel # PURPOSE: Sets the y axis label. # PARAMETERS: string # RETURNS: --- #=============================================================================== sub gnuplot_set_ylabel { my ( $self, $ylabel ) = @_; if ( defined $ylabel ) { $self->gnuplot_cmd( "set ylabel \"$ylabel\"" ); }; return $self; } # ---------- end of subroutine gnuplot_set_ylabel ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_set_xrange # PURPOSE: Sets the horizontal range that will be displayed. # PARAMETERS: 1. parameter: range, left value # 2. parameter: range, right value # RETURNS: --- #=============================================================================== sub gnuplot_set_xrange { my ( $self, $xleft, $xright ) = @_; if ( defined $xleft && defined $xright ) { $self->gnuplot_cmd( "set xrange [ $xleft : $xright ]" ); } return $self; } # ---------- end of subroutine gnuplot_set_xrange ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_set_yrange # PURPOSE: Sets the vertical range that will be displayed. # PARAMETERS: 1. parameter: range, low value # 2. parameter: range, high value # RETURNS: --- #=============================================================================== sub gnuplot_set_yrange { my ( $self, $yleft, $yright ) = @_; if ( defined $yleft && defined $yright ) { $self->gnuplot_cmd( "set yrange [ $yleft : $yright ]" ); } return $self; } # ---------- end of subroutine gnuplot_set_yrange ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_get_plotnumber # PURPOSE: Get the (internal) plot number # PARAMETERS: --- # RETURNS: object number #=============================================================================== sub gnuplot_get_plotnumber { my ( $self ) = @_; return $self->{__plotnumber}; } # ---------- end of subroutine gnuplot_get_plotnumber ---------- #=== CLASS METHOD ============================================================ # NAME: gnuplot_get_object_id # PURPOSE: Get the (internal) object number # PARAMETERS: --- # RETURNS: object number #=============================================================================== sub gnuplot_get_object_id { my ( $self ) = @_; if ( wantarray ) { return ( $self->{__objectnumber}, $self->{objectname} ); } else { return $self->{__objectnumber}; } } # ---------- end of subroutine gnuplot_get_object_id ---------- END { } # module clean-up code 1; #__END__ #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # Module Documentation #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% =head1 NAME Graphics::GnuplotIF - A dynamic Perl interface to gnuplot =head1 VERSION This documentation refers to Graphics::GnuplotIF version 1.5 =head1 SYNOPSIS use Graphics::GnuplotIF qw(GnuplotIF); my @x = ( -2, -1.50, -1, -0.50, 0, 0.50, 1, 1.50, 2 ); # x values my @y1 = ( 4, 2.25, 1, 0.25, 0, 0.25, 1, 2.25, 4 ); # function 1 my @y2 = ( 2, 0.25, -1, -1.75, -2, -1.75, -1, 0.25, 2 ); # function 2 my $plot1 = Graphics::GnuplotIF->new(title => "line", style => "points"); $plot1->gnuplot_plot_y( \@x ); # plot 9 points over 0..8 $plot1->gnuplot_pause( ); # hit RETURN to continue $plot1->gnuplot_set_title( "parabola" ); # new title $plot1->gnuplot_set_style( "lines" ); # new line style $plot1->gnuplot_plot_xy( \@x, \@y1, \@y2 ); # plot 1: y1, y2 over x $plot1->gnuplot_plot_many( \@x, \@y1, \@x, \@y2 ); # plot 1: y1 - x, y2 - x my $plot2 = Graphics::GnuplotIF->new; # new plot object $plot2->gnuplot_set_xrange( 0, 4 ); # set x range $plot2->gnuplot_set_yrange( -2, 2 ); # set y range $plot2->gnuplot_cmd( "set grid" ); # send a gnuplot command $plot2->gnuplot_plot_equation( # 3 equations in one plot "y1(x) = sin(x)", "y2(x) = cos(x)", "y3(x) = sin(x)/x" ); $plot2->gnuplot_pause( ); # hit RETURN to continue $plot2->gnuplot_plot_equation( # rewrite plot 2 "y4(x) = 2*exp(-x)*sin(4*x)" ); $plot2->gnuplot_pause( ); # hit RETURN to continue my $plot3 = GnuplotIF; # new plot object my @xyz = ( # 2-D-matrix, z-values [0, 1, 4, 9], [1, 2, 6, 15], [4, 6, 12, 27], [9, 15, 27, 54], ); $plot3->gnuplot_cmd( "set grid" ); # send a gnuplot command $plot3->gnuplot_set_plot_titles("surface"); # set legend $plot3->gnuplot_plot_3d( \@xyz ); # start 3-D-plot $plot3->gnuplot_pause( ); # hit RETURN to continue =head1 DESCRIPTION Graphics::GnuplotIF is a simple and easy to use dynamic Perl interface to B. B is a freely available, command-driven graphical display tool for Unix. It compiles and works quite well on a number of Unix flavours as well as other operating systems. This module enables sending display requests asynchronously to B through simple Perl subroutine calls. A gnuplot session is an instance of class Graphics::GnuplotIF. The constructor starts B as a separate process for each session. The plot commands are send through a I. The graphical output from B will be displayed immediately. Several independent plots can be started from one script. Each plot has its own pipe. All pipes will be closed automatically by the destructor when the script terminates. The B processes terminate when the corresponding pipes are closed. Their graphical output will now disappear (but see parameter L). Graphics::GnuplotIF is similar to C< gnuplot_i >, a C interface to B ( http://ndevilla.free.fr/gnuplot/ ), and to C< gnuplot_i++ >, a C++ interface to B ( http://jijo.cjb.net/code/cc++ ). =head1 SUBROUTINES/METHODS An object of this class represents an interface to a running B process. During the creation of an object such an process will be started for each such object. Communication is done through an unidirectional pipe; the resulting stream is write-only. Most methods return a reference to the Graphics::GnuplotIF object, allowing method calls to be chained like so: $plot1 -> gnuplot_plot_xy(\@x, \@y) -> gnuplot_reset; The exception to this are L and L, which are used to obtain specific scalar values. =head2 new The constructor creates a new B session object, referenced by a handle: $plot1 = Graphics::GnuplotIF->new( ); A few named arguments can be passed as key - value pairs (here shown with their default values): style => 'lines', # one of the gnuplot line styles (see below) title => '', # string xlabel => 'x', # string ylabel => 'y', # string xrange => [], # array reference; autoscaling, if empty xrange => [], # array reference; autoscaling, if empty plot_titles => [], # array of strings; titles used in the legend scriptfile => '', # write all plot commands to the specified file plot_also => 0, # write all plot commands to the specified file, # in addition show the plots persist => 0, # let plot windows survive after gnuplot exits # 0 : close / 1 : survive objectname => '', # an optional name for the object silent_pause => 1, # 0 suppress message from gnuplot_pause() These attributes are stored in each object. Allowed line styles are boxes dots filledcurves fsteps histeps impulses lines linespoints points steps The generated B commands can be stored to a file instead of beeing executed immediately. This file can be used as input to B, e.g. gnuplot < function_set_1.gnuplot A script file can also be used for checking the commands send to B. The objects are automatically deleted by a destructor. The destructor closes the pipe to the B process belonging to that object. The B process will also terminate and remove the graphic output. The termination can be controlled by the method L | gnuplot_pause> . =head2 GnuplotIF The short form of the constructor above (L|new>): use Graphics::GnuplotIF qw(GnuplotIF); $plot1 = GnuplotIF; This subroutine is exported only on request. =head2 gnuplot_plot_y $plot1->gnuplot_plot_y( \@y1, \@y2 ); C takes one or more array references and plots the values over the x-values 0, 1, 2, 3, ... =head2 gnuplot_plot_xy $plot1->gnuplot_plot_xy( \@x, \@y1, \@y2 ); C takes two or more array references. The first array is assumed to contain the x-values for the following function values. =head2 gnuplot_plot_xy_style %y1 = ( 'y_values' => \@y1, 'style_spec' => "lines lw 3" ); %y2 = ( 'y_values' => \@y2, 'style_spec' => "points pointtype 4 pointsize 5" ); $plot1->gnuplot_plot_xy_style( \@x, \%y1, \%y2 ); C takes one array reference and one or more hash references. The first array is assumed to contain the x-values for the following function values. The following hashes are assumed to contain pairs of y-values and individual style specifications for use in the plot command. The 'style_spec' settings are placed between C and C of B<gnuplot>'s C<plot> command. =head2 gnuplot_plot_many $plot1->gnuplot_plot_xy( \@x1, \@y1, \@x2, \@y2 ); C<gnuplot_plot_many> takes pairs of array references. Each pair represents a function and is a reference to the arrays of x- and y-values for that function. =head2 gnuplot_plot_many_style %f1 = ( 'x_values' => \@x1, 'y_values' => \@y1, 'style_spec' => "lines lw 3" ); %f2 = ( 'x_values' => \@x2, 'y_values' => \@y2, 'style_spec' => "points pointtype 4 pointsize 5" ); $plot1->gnuplot_plot_many_style( \%f1, \%f2 ); C<gnuplot_plot_many_style> takes one or more hash references. The hashes are assumed to contain array referenses to x-values and y-values and individual style specifications for use in the plot command. The 'style_spec' settings are placed between C<with> and C<title> of B<gnuplot>'s C<plot> command. =head2 gnuplot_plot_equation $plot2->gnuplot_plot_equation( # 3 equations in one plot "y1(x) = sin(x)", "y2(x) = cos(x)", "y3(x) = sin(x)/x" ); C<gnuplot_plot_equation> takes one or more B<gnuplot> function descriptions as strings. The plot ranges can be controlled by L<C<gnuplot_set_xrange>|gnuplot_set_xrange> and L<C<gnuplot_set_yrange>|gnuplot_set_yrange> . =head2 gnuplot_plot_3d $plot2->gnuplot_plot_3d( \@array ); # 3-D-plot C<gnuplot_plot_3d> takes one reference to an 2-D-array of z-values. =head2 gnuplot_pause $plot1->gnuplot_pause( [time] [,text] ); This is an emulation of the B<gnuplot> C<pause> command. It displays any text associated with the command and waits a specified amount of time or until the carriage return is pressed. The message can be suppressed by silent_pause => 0 given to the constructor (see L<new | new>). C<time> may be any constant or expression. Choosing 0 (default) will wait until a carriage return is hit, a negative value won't pause at all, and a positive number will wait the specified number of seconds. The time value and the text are stored in the object and reused. A sequence like $plot1->gnuplot_plot_y( \@y1 ); $plot1->gnuplot_pause( 5.5 ); # delay is 5.5 seconds $plot1->gnuplot_plot_y( \@y2 ); $plot1->gnuplot_pause( ); $plot1->gnuplot_plot_y( \@y3 ); $plot1->gnuplot_pause( ); will display 3 plots with 5.5 seconds delay. =head2 gnuplot_cmd $plot2->gnuplot_cmd( 'set grid', 'set timestamp "%d/%m/%y %H:%M" 0,0 "Helvetica"' ); C<gnuplot_cmd> can be used to send one or more B<gnuplot> commands, especially those not wrapped by a Graphics::GnuplotIF method. =head2 gnuplot_reset $plot1->gnuplot_reset(); Set all options set with the C<set> command to their B<gnuplot> default values. =head2 gnuplot_set_style $plot1->gnuplot_set_style( "steps" ); # new line style Sets one of the allowed line styles (see L<new | new>) in a plot command. =head2 gnuplot_set_title $plot1->gnuplot_set_title("parabola"); # new title Sets the plot title. Equivalent to the B<gnuplot> command C<set title "parabola">. =head2 gnuplot_set_xlabel $plot1->gnuplot_set_xlabel("time (days)"); Sets the x axis label. Equivalent to the B<gnuplot> command C<set xlabel "time (days)">. =head2 gnuplot_set_ylabel $plot1->gnuplot_set_ylabel("bugs fixed"); Sets the y axis label. Equivalent to the B<gnuplot> command C<set ylabel "bugs fixed">. =head2 gnuplot_set_xrange $plot1->gnuplot_set_xrange( left, right ); Sets the horizontal range that will be displayed. Equivalent to the B<gnuplot> command C<set xrange [left:right]>. =head2 gnuplot_set_yrange $plot1->gnuplot_set_yrange( low, high ); Sets the vertical range that will be displayed. Equivalent to the B<gnuplot> command C<set yrange [low:high]>. =head2 gnuplot_set_plot_titles $plot1->gnuplot_set_plot_titles( @ytitles ); Sets the list of titles used in the key for each of the y-coordinate data sets specified in subsequent calls to gnuplot_plot_xy or gnuplot_plot_y commands. This is not equivalent to a complete B<gnuplot> command; rather it adds a C<title> clause to each data set specified in a B<gnuplot> C<plot> command. =head2 gnuplot_hardcopy C<gnuplot_cmd> can be used to write a plot into a file or make a printable file by setting/resetting the terminal and the output file: $plot1->gnuplot_hardcopy( 'function1.gnuplot.ps', 'postscript', 'color lw 3' ); $plot1->gnuplot_plot_xy( \@x, \@y1, \@y2 ); $plot1->gnuplot_restore_terminal(); The 1. parameter is a file name, the 2. parameter is a B<gnuplot> terminal type, the 3. parameter is a string with additional terminal parameters (optional). The current terminal settings will be saved. =head2 gnuplot_restore_terminal Restores the saved terminal settings after a call to C<gnuplot_hardcopy()>. Output will go to C<STDOUT> again. =head3 Print a plot directly A hardcopy can be made with an appropriate output format and a pipe to a printer: $plot1->gnuplot_cmd( 'set terminal postscript', 'set output " | lpr " ' ); $plot1->gnuplot_plot_xy( \@x, \@y1, \@y2 ); $plot1->gnuplot_cmd( 'set output', 'set terminal x11' ); =head2 gnuplot_get_object_id Get the (internal) object number (and the object name): $obj_number = $plot1->gnuplot_get_object_id(); ($obj_number, $obj_name) = $plot1->gnuplot_get_object_id(); The object number is set automatically by the constructor. The object name can be set by the constructor (objectname => 'MyName'). =head2 gnuplot_get_plotnumber Get the (internal) plot number of the B<next> plot: $plot_number = $plot1->gnuplot_get_plotnumber() The plot number is set automatically by the constructor starting with 1. Each call to gnuplot_plot_y gnuplot_plot_xy gnuplot_plot_xy_style gnuplot_plot_many gnuplot_plot_many_style gnuplot_plot_equation gnuplot_plot_3d increments this number by 1. This can be used to identify single plots, e.g. with $plot->gnuplot_cmd( "set timestamp \"plot number ${plot_number} / %c\"" ); =head1 EXPORTS B<GnuplotIF> constructor, short form (see L<C<GnuplotIF> | GnuplotIF>). =head1 DIAGNOSTICS Dialog messages and diagnostic messages start with C< Graphics::GnuplotIF (object NR): ... > . C<NR> is the number of the corresponding Graphics::GnuplotIF object and output stream. NR counts the objects in the order of their generation. The gnuplot messages going to STDERR will be redirected to the file C<.gnuplot.PPP.OOO.stderr.log>. PPP is the process number, OOO is the number of the plot object (see L<C<gnuplot_get_object_id>|gnuplot_get_object_id>). =head1 CONFIGURATION AND ENVIRONMENT The environment variable DISPLAY is checked for the display. =head1 DEPENDENCIES =over 2 =item * C<gnuplot> ( http://sourceforge.net/projects/gnuplot ) must be installed. =item * The module C<Carp> is used for error handling. =item * The module C<IO::Handle> is used to handle output pipes. Your operating system must support pipes, of course. =back =head1 INCOMPATIBILITIES There are no known incompatibilities. =head1 BUGS AND LIMITATIONS $plot1->gnuplot_cmd("pause -1"); # send the gnuplot pause command does not work. Use $plot1->gnuplot_pause( ); There are no known bugs in this module. Please report problems to author. Patches are welcome. =head1 AUTHOR Dr.-Ing. Fritz Mehner (mehner@fh-swf.de) =head1 CREDITS Stephen Marshall (smarshall at wsi dot com) contributed C<gnuplot_set_plot_titles>. Georg Bauhaus (bauhaus at futureapps dot de) contributed C<gnuplot_plot_xy_style>. Bruce Ravel (bravel at bnl dot gov) contributed C<gnuplot_plot_many> and C<gnuplot_plot_many_style> and made method calls chainable. =head1 LICENSE AND COPYRIGHT Copyright (C) 2005-2008 by Fritz Mehner This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perldoc perlartistic. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =head1 SEE ALSO C<gnuplot(1)>. =cut �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Graphics-GnuplotIF-1.6/Makefile.PL������������������������������������������������������������������0000644�0001750�0000144�00000001046�10631730123�016131� 0����������������������������������������������������������������������������������������������������ustar �mehner��������������������������users������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Graphics::GnuplotIF', AUTHOR => 'Dr.-Ing. Fritz Mehner <mehner@fh-swf.de>', VERSION_FROM => 'lib/Graphics/GnuplotIF.pm', ABSTRACT_FROM => 'lib/Graphics/GnuplotIF.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'version' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Graphics-GnuplotIF-*' }, ); ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Graphics-GnuplotIF-1.6/README�����������������������������������������������������������������������0000644�0001750�0000144�00000003447�11533757647�015074� 0����������������������������������������������������������������������������������������������������ustar �mehner��������������������������users������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������GnuplotIF version 1.6 ===================== GnuplotIF is a simple and easy to use Perl interface to gnuplot. gnuplot is a freely available, command-driven graphical display tool for Unix. It compiles and works quite well on a number of Unix flavours as well as other operating systems. The following module enables sending display requests to gnuplot through simple Perl subroutine calls. GnuplotIF starts gnuplot as a separate process. The plot commands are send through a pipe. The graphical output from gnuplot will be displayed immediately. Several independent plots can be started from one script. Each plot has its own pipe. All pipes will be closed automatically when the script terminates. The gnuplot processes terminate when the corresponding pipes are closed. Their graphical output will now disappear. GnuplotIF is similar to gnuplot_i , a C interface to gnuplot ( http://ndevilla.free.fr/gnuplot/ ), and to gnuplot_i++ , a C++ interface to gnuplot ( http://jijo.cjb.net/code/cc++ ). INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: gnuplot ( http://sourceforge.net/projects/gnuplot ) must be installed. The module IO::Handle is used to handle output pipes. Your operating system must support pipes, of course. The environment variable DISPLAY is checked for the display. COPYRIGHT AND LICENCE Copyright (C) 2005-2011 by Fritz Mehner This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Graphics-GnuplotIF-1.6/Changes����������������������������������������������������������������������0000644�0001750�0000144�00000002362�11533772551�015471� 0����������������������������������������������������������������������������������������������������ustar �mehner��������������������������users������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Revision history for Perl extension GnuplotIF. 1.0 Thu Jul 28 11:00:14 2005 - original version; created by h2xs 1.23 with options -XA -n GnuplotIF 1.1 Aug 27 2006 - method gnuplot_set_plot_titles added (thanks to Stephen Marshall) 1.2 Jun 06 2007 - tests improved 1.3 Oct 13 2007 - Module no longer dies if no display is available (allows batch mode). - Method gnuplot_plot_xy_style (thanks to Georg Bauhaus) 1.3.1 Nov 10 2007 - All prints to pipes will be checked. - New test: 8 pipes open in parallel. 1.4 Nov 28 2007 - Plot window can survive after gnuplot exits. - Plot can be stored to a script file instead of beeing executed immediately. - New method gnuplot_plot_3d makes 3-D-plots from arrays. - New method gnuplot_hardcopy writes a plot into a file for printing. - New method gnuplot_restore_terminal restores terminal settings before the last hardcopy. 1.5 June 11 2008 - Method gnuplot_plot_many() and gnuplot_plot_many_style for x-y-plots not sharing an x-axis. - Most method calls can now be chained (thanks to Bruce Ravel for both). 1.6 March 3 2011 - gnuplot_pause() not working as advertised. - New constructor argument 'plot_also': write all plot commands to a file, in addition show the plots. ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Graphics-GnuplotIF-1.6/META.yml���������������������������������������������������������������������0000644�0001750�0000144�00000001112�11533773702�015436� 0����������������������������������������������������������������������������������������������������ustar �mehner��������������������������users������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������--- #YAML:1.0 name: Graphics-GnuplotIF version: 1.6 abstract: A dynamic Perl interface to gnuplot author: - Dr.-Ing. Fritz Mehner <mehner@fh-swf.de> license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Test::More: 0 version: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.56 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Graphics-GnuplotIF-1.6/MANIFEST���������������������������������������������������������������������0000644�0001750�0000144�00000000244�10631730123�015307� 0����������������������������������������������������������������������������������������������������ustar �mehner��������������������������users������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Build.PL Changes MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/Graphics/GnuplotIF.pm t/00.load.t t/pod-coverage.t t/pod.t t/GnuplotIF.t ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������