Forum: Ruby gnuplot timeseries

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rob R. (Guest)
on 2009-04-23 01:16
Attachment: Picture_1.png (0 Bytes)
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
Phlip (Guest)
on 2009-04-23 01:41
(Received via mailing list)
> # 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/cruise...

...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!
Rob R. (Guest)
on 2009-04-23 02:02
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/cruise...
>
> ...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.
This topic is locked and can not be replied to.