http://www.perlmonks.org?node_id=721599

dHarry has asked for the wisdom of the Perl Monks concerning the following question:

Dear venerable wise ones

I want to create some 2D plots and went for Chart::Gnuplot

Both Chart::Gnuplot and gnuplot install fine. Gnuplot works. When I try a simple Perl example it fails, error message: 'gnuplot' is not recognized as an internal or external command,operable program or batch file. Not a surprise since Chart::Gnuplot issues a gnuplot command. Under Windows this is not available, instead it’s called wgnuplot.exe. I googled and tried a few suggested solutions, like creating a gnuplot.bat file pointing to the right file, this fails. Next I investigated building gnuplot from the sources but then you end up with the same wgnuplot.exe.

Has anybody made Chart::Gnuplot with gnuplot work under Windows XP? Or is this yet another reason to change OS?!

Replies are listed 'Best First'.
Re: Chart::Gnuplot and Windows XP
by BrowserUk (Patriarch) on Nov 05, 2008 at 11:25 UTC
    'gnuplot' is not recognized as an internal or external command,operable program or batch file.

    If you put a file called gnuplot.bat somewhere it can be found through your path environment variable, it should work fine.

    Or you could rename (or make a copy of) wgnuplot.exe called gnuplot.exe. Again, it would need to be located somewhere on your path.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Changing the name of the executable gives an "Invalid Parameter - 90" error.

      Using a .bat file: "C:\gnuplot\binaries\wgnuplot.exe" %1 results in the call C:\workspace\Testbed>"C:\gnuplot\binaries\wgnuplot.exe" \tmp\NTEVfipQVM/plot and gives the same error.

        I suspect, but am not in a position to confirm just now, that the problem is this forward slash:

        \tmp\NTEVfipQVM/plot ................^

        And that if you modified Chart::Gnuplot something along the lines of:

        sub new { my ($class, %hash) = @_; # Create temporary file to store Gnuplot instructions if (!defined $hash{_multiplot}) # if not in multiplot mode { my $dirTmp = tempdir(CLEANUP => 1, DIR => '/tmp'); ########### change here $hash{_script} = $^O eq 'MSWin32' ? "$dirTmp\plot" : "$dirTmp/ +plot";

        Then it might work.

        Of course, there are probably other places (like the line above) that might need similar treatment--and there are certainly better ways (File::Spec and friends) of making the path handling properly cross-platform--, but a few simple changes like this might allow you to get on with your work.

        And if you fed what changes you need, back to the module author, they might be able to integrate them back into the next release.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Chart::Gnuplot and Windows XP
by Anonymous Monk on Nov 05, 2008 at 11:27 UTC
    Has anybody made Chart::Gnuplot with gnuplot work under Windows XP? Or is this yet another reason to change OS?!
    Wow, just wow, the drama :)
    # Create chart object and specify the properties of the chart my $chart = Chart::Gnuplot->new( output => "fig/simple.png", title => "Simple testing", xlabel => "My x-axis label", ylabel => "My y-axis label", .... gnuplot => "dramaqueen.exe", );
    http://search.cpan.org/~kwmak/Chart-Gnuplot-0.05/lib/Chart/Gnuplot.pm#gnuplot

      Bless you brother, I completely missed the gnuplot => "path to exe" option. However, also in this case I get an Invalid Parameter - 90 error message.

        Based on your other reply, it seems that you are mixing "/" and "\" directory separators in your chart's file name. Try not to... :-)

        the file name should either be
        \tmp\NTEVfipQVM\plot or
        /tmp/NTEVfipQVM/plot but not
        \tmp\NTEVfipQVM/plot ...

        []s, HTH, Massa (κς,πμ,πλ)
        However, also in this case I get an Invalid Parameter - 90 error message

        I'm starting to get the feeling that the gnuplot executable and wgnuplot.exe must take different arguments.

        Cheers,
        Rob
        Hmm, works for me :/

        I used gp424win32.zip from here.

        I also removed DIR => '/tmp' from Gnuplot.pm, because I like my existing temp directory just fine.

Re: Chart::Gnuplot and Windows XP
by BrowserUk (Patriarch) on Nov 05, 2008 at 23:38 UTC

    A little more information now I've gotten to downloading the gnuplot package. There seem to be a lot of problems with Chart::Gnuplot.

    Amongst others,

    • you need to code the output file thusly:     output => 'c:\\\\test\\\\test.png', in order to get 'c:\\test\\test.png' into the command file. Otherwise you get the Invalid Parameter - 90 error.

      You'll also get that same error if the output file already exists.

    • The output produced (once you get it to actually produce output!), is initially not the .png you are specify, but rather an EPS format file. (with a .png extension).

      Chart::Gnuplot then goes looking for a convert utility (from the ImageMagick distribution), to translate that into the required .png (gif, bmp etc.)

      Depending upon the output format required, it will also go looking for a couple of other utilities, ps2pdf, pdf2ps which are also not a part of the distribution. I'm not sure where they come from.

    It looks like it would take some serious work (and therefore a serious need!) to get this working under windows.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      For me this works on Windows XP:
      my $chart = Chart::Gnuplot->new( gnuplot => $gnuplotpath, terminal => "gif transparent", output => $filename, );
      If terminal is not specified I also get the Invalid Parameter - 90 error.
        I also got the -90 error in windows because I did not have ghostscript installed. I installed it and it worked. Also I got errors if I did not set the PATH envt variable or else give the full path to gnuplot.exe and convert.exe.
Re: Chart::Gnuplot and Windows XP
by Anonymous Monk on Jan 14, 2013 at 04:09 UTC
    Hi guys, very new in installing extensions of PERL. Want to use GNUPLOT for completing a PERL code. Using Win 7 professional (32 bit). Unpacked "Chart-Gnuplot-0.17.tar.gz" and created a "Chart" subdirectory in the lib directory (by intuition since I did not read instructions on installing perl extensions ==> hate to read complicated instructions!!)... apparently it starts working when trying an example but process gets stacked at the beginning of Gnuplot.pm (line 5) since apparently the File::Copy extension can not do the "move" operation .... does anyone know how to deal with this problem?.... my knowledge of PERL is very limited... I am not an IT guy but just a common PERL user for some engineering tasks... I would appreciate any help on this matter but explained in a very simple way. Thanks in advance folks: raulito_vz@yahoo.com

      windows comes with a convert.exe which is nothing like the imagemagick convert.exe

      You need to manage your %PATH, police your $ENV{PATH} / use Env '@PATH';

Re: Chart::Gnuplot and Windows XP
by vagabonding electron (Curate) on May 25, 2015 at 14:38 UTC

    Yes, it works on Windows for me.

    You should set the path to the executable as already mentioned. Note that there are wgnuplot.exe and gnuplot.exe in the bin directory, you need gnuplot.exe, not the former.

    Without setting terminal option it works only with postscript files. As mentioned in the pod you should use e.g. terminal => 'png' to plot in the other formats.

    There is a nice set of examples that comes with the installation.

    The following example runs under Win7 with Gnuplot 5.

    #!/perl use strict; use warnings FATAL => qw(all); use Chart::Gnuplot; my $chart = Chart::Gnuplot->new( output => "X:/TMP/multiplot.png", gnuplot => "C:/gnuplot5/gnuplot/bin/gnuplot.exe", terminal => 'png', ); my $left = Chart::Gnuplot->new(); my $sine = Chart::Gnuplot::DataSet->new( func => "sin(x)", ); $left->add2d($sine); my $center = Chart::Gnuplot->new(); my $cosine = Chart::Gnuplot::DataSet->new( func => "cos(x)", ); $center->add2d($cosine); my $right = Chart::Gnuplot->new(); my $tangent = Chart::Gnuplot::DataSet->new( func => "tan(x)", ); $right->add2d($tangent); $chart->multiplot([ [$left, $center, $right] ]);