gnuplot timeseries

Discussion in 'Ruby' started by Rob Redmon, Apr 22, 2009.

  1. Rob Redmon

    Rob Redmon Guest

    Does anyone have an example of plotting a timeseries with gnuplot and
    setting the xrange? Why doesn't the following snippet work as expected?
    It produces the attached.

    require 'rubygems'
    require 'gnuplot'
    require 'date'
    obs_times = Array.new
    data = Array.new
    24.times { |h| obs_times << DateTime.new( 2009, 1, 1, h ); data <<
    rand() }
    # doesn't work either
    # 24.times { |h| obs_times << "2009-1-1 #{h}:00:00"; data <<
    rand() }

    Gnuplot.open do |gp|
    Gnuplot::plot.new( gp ) do |plot|

    # causes error plot.xrange
    "[\"2009-01-01T00:00:00+00:00\":\"2009-01-01T23:59:00+00:00\"]"
    plot.data << Gnuplot::DataSet.new( [ obs_times, data ] ) do |ds|
    ds.with = "points"
    ds.linewidth = 4
    end
    end
    end

    Attachments:
    http://www.ruby-forum.com/attachment/3609/Picture_1.png

    --
    Posted via http://www.ruby-forum.com/.
    Rob Redmon, Apr 22, 2009
    #1
    1. Advertising

  2. Rob Redmon

    Phlip Guest

    > # causes error plot.xrange
    > "[\"2009-01-01T00:00:00+00:00\":\"2009-01-01T23:59:00+00:00\"]"


    I'm not sure where the +00:00 comes from.

    This post...

    http://www.oreillynet.com/ruby/blog/2008/03/cruisecontrol_charts.html

    ....shows how to format the time and build a range:

    def timefmt; '%Y/%d/%m-%H:%M'; end

    def fetch_codelines(stat, fields)
    return stat.values_at(*fields).map{|values| values['codelines'] }.sum
    end

    def ftime(timestamp)
    Time.at(timestamp).strftime(timefmt)
    end
    ....
    plot.xrange "['#{ ftime(mini) }':'#{ ftime(maxi) }']"

    I admit the documentation on that technique, in both Gnuplot.rb and gnuplot,
    are very scarce!
    Phlip, Apr 22, 2009
    #2
    1. Advertising

  3. Rob Redmon

    Rob Redmon Guest

    Phlip wrote:
    >> # causes error plot.xrange
    >> "[\"2009-01-01T00:00:00+00:00\":\"2009-01-01T23:59:00+00:00\"]"

    >
    > I'm not sure where the +00:00 comes from.


    That's the default format of DateTime.new.to_s

    >
    > This post...
    >
    > http://www.oreillynet.com/ruby/blog/2008/03/cruisecontrol_charts.html
    >
    > ...shows how to format the time and build a range:
    >
    > def timefmt; '%Y/%d/%m-%H:%M'; end
    >
    > def fetch_codelines(stat, fields)
    > return stat.values_at(*fields).map{|values| values['codelines'] }.sum
    > end
    >
    > def ftime(timestamp)
    > Time.at(timestamp).strftime(timefmt)
    > end
    > ...
    > plot.xrange "['#{ ftime(mini) }':'#{ ftime(maxi) }']"
    >
    > I admit the documentation on that technique, in both Gnuplot.rb and
    > gnuplot,
    > are very scarce!


    Thanks for the ideas. Ruby originated gnuplot examples are so scarce
    that I've been looking (in vain) for another package that as lightweight
    but better documented.
    --
    Posted via http://www.ruby-forum.com/.
    Rob Redmon, Apr 22, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alythh

    Gnuplot module

    Alythh, Jul 23, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,906
    Yuchung Cheng
    Jul 28, 2003
  2. Tintifax

    installing scikits.timeseries

    Tintifax, Dec 23, 2010, in forum: Python
    Replies:
    0
    Views:
    476
    Tintifax
    Dec 23, 2010
  3. JB
    Replies:
    1
    Views:
    361
    Vlastimil Brom
    Jul 21, 2011
  4. Peter Booth

    Ruby/MySQL/Rails timeseries QN

    Peter Booth, Nov 10, 2006, in forum: Ruby
    Replies:
    0
    Views:
    128
    Peter Booth
    Nov 10, 2006
  5. Davide Dalmasso

    Broadcasting TimeSeries

    Davide Dalmasso, Sep 4, 2013, in forum: Python
    Replies:
    1
    Views:
    141
    Terry Reedy
    Sep 4, 2013
Loading...

Share This Page