In [1]:
require 'daru'
require 'gnuplotrb'
include GnuplotRB

index  = Daru::DateTimeIndex.date_range(:start => DateTime.new(2012,2,1), periods: 100)
vector = Daru::Vector.new(Array.new(10){ [1,2,3,4,5].shuffle }.flatten, index: index)
Out[1]:
Daru::Vector:30499660 size: 100
nil
2012-02-01T00:00:00+00:003
2012-02-02T00:00:00+00:005
2012-02-03T00:00:00+00:004
2012-02-04T00:00:00+00:001
2012-02-05T00:00:00+00:002
2012-02-06T00:00:00+00:003
2012-02-07T00:00:00+00:001
2012-02-08T00:00:00+00:004
2012-02-09T00:00:00+00:005
2012-02-10T00:00:00+00:002
2012-02-11T00:00:00+00:005
2012-02-12T00:00:00+00:004
2012-02-13T00:00:00+00:002
2012-02-14T00:00:00+00:001
2012-02-15T00:00:00+00:003
2012-02-16T00:00:00+00:002
2012-02-17T00:00:00+00:005
2012-02-18T00:00:00+00:003
2012-02-19T00:00:00+00:001
2012-02-20T00:00:00+00:004
2012-02-21T00:00:00+00:002
2012-02-22T00:00:00+00:004
2012-02-23T00:00:00+00:003
2012-02-24T00:00:00+00:001
2012-02-25T00:00:00+00:005
2012-02-26T00:00:00+00:004
2012-02-27T00:00:00+00:005
2012-02-28T00:00:00+00:003
2012-02-29T00:00:00+00:002
2012-03-01T00:00:00+00:001
2012-03-02T00:00:00+00:004
2012-03-03T00:00:00+00:001
......
2012-05-10T00:00:00+00:00
In [2]:
vector_plot = Plot.new([vector, with: 'linespoints'], yrange: 0..6)
Out[2]:
Gnuplot Produced by GNUPLOT 5.0 patchlevel rc2 0 1 2 3 4 5 6 26 Jan 2012 02 Feb 2012 09 Feb 2012 16 Feb 2012 23 Feb 2012 01 Mar 2012 08 Mar 2012 15 Mar 2012 22 Mar 2012 gnuplot_plot_1
In [3]:
vector_plot.xrange('["2012-02-16":"2012-02-26"]')
Out[3]:
Gnuplot Produced by GNUPLOT 5.0 patchlevel rc2 0 1 2 3 4 5 6 16 Feb 2012 17 Feb 2012 18 Feb 2012 19 Feb 2012 20 Feb 2012 21 Feb 2012 22 Feb 2012 23 Feb 2012 24 Feb 2012 25 Feb 2012 26 Feb 2012 gnuplot_plot_1
In [4]:
df = Daru::DataFrame.new({
    'Sales by Bill' => [1, 2, 3, 4, 5].shuffle,
    'Sales by Martin' => [1, 2, 3, 4, 5].shuffle,
  },
  index: index
)
In [5]:
p = Plot.new(
  df,
  style_data: 'linespoints',
  yrange: 0..6
)
Out[5]:
Gnuplot Produced by GNUPLOT 5.0 patchlevel rc2 0 1 2 3 4 5 6 01 Feb 2012 01 Feb 2012 02 Feb 2012 02 Feb 2012 03 Feb 2012 03 Feb 2012 04 Feb 2012 04 Feb 2012 05 Feb 2012 Sales by Bill Sales by Bill Sales by Martin Sales by Martin

Format of datetime may be changed with format_x option:

In [6]:
p.format_x('%d/%m\n%H:%M')
Out[6]:
Gnuplot Produced by GNUPLOT 5.0 patchlevel rc2 0 1 2 3 4 5 6 01/02 00:00 01/02 12:00 02/02 00:00 02/02 12:00 03/02 00:00 03/02 12:00 04/02 00:00 04/02 12:00 05/02 00:00 Sales by Bill Sales by Bill Sales by Martin Sales by Martin