use IPC::Open3;
my $mw = MainWindow->new( -title => 'Perl/Tk-GNUPLOT ' );
my $tframe = $mw->Frame()->pack();
my $canvas = $tframe->Canvas(-cursor => "crosshair",-bg => 'white', -height =>500, -width =>500, )->pack(-side=>'left',-expand=>1,-fill=>'both');
my $tframe1 = $tframe->Frame()->pack(-side=>'right',-padx=>0);
my $pid = open3( \*gIN, \*gOUT, \*gERR,"/usr/bin/gnuplot" ) || die;
$mw->fileevent( \*gOUT, readable => \&read_out );
print gIN "set term tkcanvas perltk interactive\n";
my $bframe = $mw->Frame->pack();
my $startbut = $bframe->Button( -text=>'Start', -command=> \&start)->pack(-side=>'left');
$mw->update;
MainLoop;
sub start{
my $string =<<"EOF";
###########################
set key at screen 1, 0.9, 0 right top vertical Right noreverse enhanced autotitle nobox
set style textbox opaque margins 0.5, 0.5 noborder
set view 60, 30, 1, 1.1
set samples 25, 25
set isosamples 26, 26
set contour base
set cntrlabel format '%8.3g' font ',7' start 5 interval 20
set cntrparam order 8
set cntrparam bspline
set style data lines
set title "contour of Sinc function"
set xlabel "X axis"
set ylabel "Y axis"
set zlabel "Z "
set zlabel offset character 1, 0, 0 font "" textcolor lt -1 norotate
set zrange [ -1.00000 : 1.00000 ] noreverse nowriteback
splot [-12:12.01] [-12:12.01] sin(sqrt(x**2+y**2)) / sqrt(x**2+y**2)
#############################
EOF
print gIN "$string\n";
}
sub read_out {
my $buffer = <gOUT>;
my $can = $canvas;
eval($buffer);
}
No comments:
Post a Comment