how to call gnuplot from ruby?

Discussion in 'Ruby' started by Pen Ttt, May 27, 2010.

  1. Pen Ttt

    Pen Ttt Guest

    i want to call gnuplot from ruby,my ruby script:
    `gnuplot` <<EOF
    plot sin(x)
    EOF


    [email protected]:~$ ruby /home/pt/r.rb ,then i get :

    G N U P L O T
    Version 4.2 patchlevel 6
    last modified Sep 2009
    System: Linux 2.6.32-22-generic

    Copyright (C) 1986 - 1993, 1998, 2004, 2007 - 2009
    Thomas Williams, Colin Kelley and many others

    Type `help` to access the on-line reference manual.
    The gnuplot FAQ is available from http://www.gnuplot.info/faq/

    Send bug reports and suggestions to
    <http://sourceforge.net/projects/gnuplot>


    Terminal type set to 'wxt'
     
    Pen Ttt, May 27, 2010
    #1
    1. Advertisements

  2. With popen:

    IO.popen('gnuplot', 'w') { |io|
    io.puts "plot sin(x)"
    }

    If you want easier control for reading/writing, use open3.

    B.D.
     
    Benoit Daloze, May 27, 2010
    #2
    1. Advertisements

  3. Pen Ttt

    Pen Ttt Guest

    IO.popen('gnuplot', 'w') { |io|
    io.puts "plot sin(x)"
    }
    i tested ,it's ok
    but i don't understand why is ('gnuplot', 'w'),why is not ('gnuplot',
    'r'),
    i call gunplot from ruby to get gnuplot's output ,so maybe it's
    ('gnuplot', 'r'),
    when i use ('gnuplot', 'r'), can't get what i want,
    could you tell me the reason of ('gnuplot', 'w')?
     
    Pen Ttt, May 28, 2010
    #3
  4. Pen Ttt

    Pen Ttt Guest

    i don't know the difference of w and r.
    program_a1:
    f=IO.popen("gunzip -c ~/grid.zip","w")
    while line=f.gets
    print line
    end
    program_a2:
    f=IO.popen("gunzip -c ~/grid.zip","r")
    while line=f.gets
    print line
    end
    program_a1 and program_a2 all can run ,what's the difference?

    there is game--freeciv installed in my computer.
    programb1:
    File.popen("/usr/games/civ","w") do |pipe|
    quote = pipe.gets
    puts quote
    end

    programb2:
    File.popen("/usr/games/civ","r") do |pipe|
    quote = pipe.gets
    puts quote
    end
    program_b1 and program_b2 all can run ,what's the difference?
     
    Pen Ttt, May 28, 2010
    #4
  5. Pen Ttt

    Robert Dober Guest

    you are writing to the handle, right?
    BTW were there not some Ruby bindings for Gnuplot, not sure though.
    HTH
    R.
     
    Robert Dober, May 28, 2010
    #5
  6. There is a gnuplot gem which IIRC makes the gnuplot interface more
    object oriented.

    I wrote a library that retains the native gnuplot command interface, but
    improves the experience in other ways (handling tempfiles and fixing
    some problems with window persistence and zombie processes). See this
    thread, for example:

    http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/b69fce4b8b6b002b
     
    Joel VanderWerf, May 28, 2010
    #6
  7. The latest version of the gnuplot gem is 2.3.1, but I'm unable to find
    any documentation online (or even a homepage) that is even remotely up
    to date.
     
    Lars Haugseth, Jun 1, 2010
    #7
  8. http://rgplot.rubyforge.org/

    It look a little out of date, but maybe it helps?
     
    Joel VanderWerf, Jun 1, 2010
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.