hello
i am running winxp with perl 10, and have tried to run gnuplot to output the plot to the tkcanvas , i have used zentara example here http://www.perlmonks.com/?node_id=592246 to produce a nice picture http://img695.imageshack.us/img695/3775/plot.jpg, the code is listed below,
just 3 problems, in the first run of the program i have an error message :""Use of uninitialized value in subroutine entry at "" ie about the line "$gnuplot->($canvas);"
in the second run the program run without problems; it seems it is running the previous created plot.pl.
second problem: is that once exited the gnuplot still running in memory; how to close it and all the processes.
the third problem: it seems that the tkcanvas can't display 3D plots such as plotting "splot sin(x*y/20)\n"
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ROText; use IPC::Open3; $|++; my $mw = MainWindow->new; my $canvas = $mw->Canvas( -bg => 'white', -height =>400, -width =>500, )->pack(); my $button = $mw -> Button(-text => "Quit", -command => \&quit)->pack(-side=>'left'); my $text = $mw->ROText(-bg=>'white') ->pack( -fill => 'both', -expand => 1 ); $text->tagConfigure( 'red', -foreground => 'red' ); my $pid = open3( \*IN, \*OUT, \*ERR, "c:/gnuplot/bin/gnuplot.exe" ) || + die; $mw->fileevent( \*OUT, readable => \&read_out ); $mw->fileevent( \*ERR, readable => \&read_err ); print IN "set term tkcanvas perltk interactive\n"; print IN "set output \'plot.pl\'\n"; #print IN "a=1\n"; #print IN "plot a\n"; #print IN "plot sin(x)/x\n"; #print IN "splot sin(x*y/20)\n"; print IN "plot sin(x) title 'Sine Function', tan(x) title 'Tangent'\n" +; my $gnuplot = do "plot.pl"; $gnuplot->($canvas); MainLoop; sub read_out { } sub read_err { print "read_err()\n"; my $num = sysread(ERR, my $buffer, 1024 ); $text->insert( 'end', $buffer, 'red' ); } sub quit{close $pid; exit}
on the other hand in the same zentara page there is a second solution to plot the graphic directly to the canvas, i was not able to run the code ,just the canvas without plot, the same is the superformula example http://www.perlmonks.com/?node_id=592338 i got an error message (open3: Can't locate auto/Tk/ROText/FILENO.al in @INC (@INC contains: c:/perl/sit e/lib c:/perl/lib .) at c:/perl/site/lib/Tk/Derived.pm line 469 ) related to the presence of "tie(*STDOUT, 'Tk::Text', $text);" i wish zentara or someone to make those examples available for windows systems, thanks
at last i have found a nice example in the book "Gnuplot in Action" to run gnuplot from perl: it is directing the output to graph.png file http://img412.imageshack.us/img412/1378/grapht.png
open PROC, "| c:/gnuplot/bin/gnuplot.exe" || die "Could not start gnup +lot: $!"; #above :the first character in the filename is a pipe symbol (|) print PROC "set xlabel 'Time'; set ylabel 'Amplitude';"; print PROC "set o 'graph.png';"; print PROC "set t png;"; print PROC "plot '-' u 1:2 t 'data' w l\n"; for( $x = 0.0; $x <= 10.0; $x += 0.1 ) { $y = exp(-$x/5)*sin( $x ); print PROC "$x $y\n"; } print PROC "e\n"; close PROC;
thanks for your patience

In reply to gnuplot output to tkcanvas by tallulah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.