class Rust::Plots::ScatterPlot
Public Class Methods
new(x = nil, y = nil, **options)
click to toggle source
Calls superclass method
Rust::Plots::BasePlot::new
# File lib/rust-plots.rb, line 138 def initialize(x = nil, y = nil, **options) super() @series = [] if x && y self.series(x, y, options) end end
Public Instance Methods
lines()
click to toggle source
# File lib/rust-plots.rb, line 158 def lines() self['type'] = "l" return self end
lines_and_points()
click to toggle source
# File lib/rust-plots.rb, line 170 def lines_and_points() self['type'] = "b" return self end
points()
click to toggle source
# File lib/rust-plots.rb, line 164 def points() self['type'] = "p" return self end
series(x, y, **options)
click to toggle source
# File lib/rust-plots.rb, line 146 def series(x, y, **options) @series << [x, y, options] return self end
thickness(t)
click to toggle source
# File lib/rust-plots.rb, line 152 def thickness(t) self['lwd'] = t return self end
Protected Instance Methods
_show()
click to toggle source
# File lib/rust-plots.rb, line 177 def _show() first = true palette = self.palette(@series.size) i = 0 base_options = {} unless @options['xlim'] x_values = @series.map { |v| v[0] }.flatten y_values = @series.map { |v| v[1] }.flatten base_options[:xlim] = [x_values.min, x_values.max] base_options[:ylim] = [y_values.min, y_values.max] end @series.each do |x, y, options| options = options.merge(base_options) Rust["plotter.x"] = x Rust["plotter.y"] = y function = nil if first function = Rust::Function.new("plot") first = false else function = Rust::Function.new("lines") end augmented_options = {} augmented_options['col'] = options[:color] || palette[i] augmented_options['xlim'] = options[:xlim] if options[:xlim] augmented_options['ylim'] = options[:ylim] if options[:ylim] function.options = self._augmented_options(augmented_options) function.arguments << Rust::Variable.new("plotter.x") function.arguments << Rust::Variable.new("plotter.y") function.call i += 1 end return self end