DARU (Data Analysis in RUby) is a library for storage, analysis, manipulation and visualization of data. You can find information about daru in its repository.
GnuplotRB takes from Daru::Vector or Daru::DataFrame name as dataset's title and index column as xtic. Example:
In [1]:
require 'daru'
require 'gnuplotrb'
include GnuplotRB
include GnuplotRB::Fit
df = Daru::DataFrame.new({
Build: [312, 630, 315, 312],
Test: [525, 1050, 701, 514],
Deploy: [215, 441, 370, 220]
},
index: ['Run A', 'Run B', 'Run C', 'Run D']
)
df[:Overall] = df[:Build] + df[:Test] + df[:Deploy]
df
Out[1]:
When you pass DataFrame to Plot.new it uses every column of DataFrame as a dataset with column name as dataset title:
In [2]:
from_daru = Plot.new(
df,
style_data: 'lines',
yrange: 0..2200,
xlabel: 'Number of test',
ylabel: 'Time, s',
title: 'Time spent to run deploy pipeline'
)
Out[2]:
In [3]:
from_daru.options(
style_data: 'histograms',
style_fill: 'pattern border'
)
Out[3]:
Datasets may be initialized both with Array or DataFrame:
In [4]:
Plot.new([df[:Overall], with: 'lines'])
Out[4]:
In [5]:
rows = (1..30).map do |i|
[i**2 * (rand(4) + 3) / 5, rand(70)]
end
df = Daru::DataFrame.rows(rows, order: [:Value, :Error], name: 'Confidence interval')
random_points = Plot.new(
[df[:Value], with: 'lines', title: 'Average value'],
[df, with: 'err']
)
Out[5]:
ok, and now lets try to fit it with polynomial:
In [6]:
poly = fit_poly(df, degree: 5)
random_points.add_dataset(poly[:formula_ds])
Out[6]:
In [7]:
df = Daru::DataFrame.new({
a: Array.new(100) {|i| i},
b: 100.times.map{rand}
},
name: 'Scatter example'
)
Plot.new([df, pt: 6, ps: 1, using: '2:3'], xrange: -10..110, yrange: -0.1..1.1)
Out[7]:
In [8]:
frames = 100.times.map do |i|
Plot.new([df.row[0..i], using: '2:3', pt: 6, ps: 1])
end
Animation.new(*frames, xrange: -10..110, yrange: -0.1..1.1)
Out[8]: