Module: Daru::Plotting::DataFrame
- Included in:
- DataFrame
- Defined in:
- lib/daru/plotting/dataframe.rb
Instance Method Summary collapse
-
#plot(x, y, opts = {}) ⇒ Object
Plots a DataFrame with Nyaplot on IRuby using the given options.
Instance Method Details
#plot(x, y, opts = {}) ⇒ Object
Plots a DataFrame with Nyaplot on IRuby using the given options.
Arguments
+x+ - Vector name to be used for x-axis
+y+ - Vector name to be used for y-axis
Options
type - Type of plot (scatter, bar, histogram)
title - Title of plot
x_label - X - label
y_label - Y - label
tooltip_contents - Contents of the tooltip. Array of vector names
fill_by - Vector name by which each plotted element is colored
shape_by- Vector name by which dots in a scatter plot are shaped
Usage
df = Daru::DataFrame.new({a:[0,1,2,3,4], b:[10,20,30,40,50]})
df.plot :a, :b, type: :bar, title: "Awesome plot"
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/daru/plotting/dataframe.rb', line 25 def plot x, y, opts={} = { type: :scatter, title: "#{@name}", }.merge(opts) plot = Nyaplot::Plot.new p = plot.add_with_df(Nyaplot::DataFrame.new(self.to_a[0]), [:type], x, y) plot.x_label [:x_label] if [:x_label] plot.y_label [:y_label] if [:y_label] p.tooltip_contents [:tooltip_contents] if [:tooltip_contents] if [:fill_by] or [:shape_by] p.color Nyaplot::Colors.qual p.fill_by [:fill_by] if [:fill_by] p.shape_by [:shape_by] if [:shape_by] end plot.show end |