Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > gnuplot timeseries

Reply
Thread Tools

gnuplot timeseries

 
 
Rob Redmon
Guest
Posts: n/a
 
      04-22-2009
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:lot.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:ataSet.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/.

 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      04-22-2009
> # 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/...ol_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!


 
Reply With Quote
 
 
 
 
Rob Redmon
Guest
Posts: n/a
 
      04-22-2009
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/...ol_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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scikits.timeseries for 2.7 JB Python 1 07-21-2011 05:30 PM
installing scikits.timeseries Tintifax Python 0 12-23-2010 06:43 PM
Ruby/MySQL/Rails timeseries QN Peter Booth Ruby 0 11-10-2006 04:08 AM
Calling GnuPlot from Java lhaslem@bigfoot.com Java 0 01-07-2005 10:27 PM
Gnuplot module Alythh Perl 1 07-28-2003 06:30 AM



Advertisments