Class: ML::Data::Plotter
- Inherits:
-
Object
- Object
- ML::Data::Plotter
- Defined in:
- lib/data/plotter.rb
Overview
Plotting the data to svg
Instance Method Summary collapse
-
#dot(points, shape = "circle", color = "#000") ⇒ Object
Plotting points with shape and color.
-
#initialize(x_range = 100, y_range = 100, x_size = 100, y_size = 100) {|_self| ... } ⇒ Plotter
constructor
Initializer of plotter.
-
#line(points, color = "#000") ⇒ Object
Plotting line with color.
-
#to_svg ⇒ String
Convert to svg.
Constructor Details
#initialize(x_range = 100, y_range = 100, x_size = 100, y_size = 100) {|_self| ... } ⇒ Plotter
Initializer of plotter
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/data/plotter.rb', line 13 def initialize x_range = 100, y_range = 100, x_size = 100, y_size = 100 @x_range = x_range @y_range = y_range @x_size = x_size @y_size = y_size @x = pv.Scale.linear(0, @x_range).range(0, @x_size) @y = pv.Scale.linear(0, @y_range).range(0, @y_size) @vis = pv.Panel.new.width(@x_size).height(@y_size) .bottom(20).left(20).right(10).top(5) @vis.add(pv.Rule).data(@y.ticks()).bottom(@y) .stroke_style(lambda {|d| d!=0 ? "#eee" : "#000"}) .anchor("left").add(pv.Label) .visible(lambda {|d| d > 0 and d < x_range}) .text(@y.tick_format) @vis.add(pv.Rule).data(@x.ticks()).left(@x) .stroke_style(lambda {|d| d!=0 ? "#eee" : "#000"}) .anchor("bottom").add(pv.Label) .visible(lambda {|d| d > 0 and d < y_range}) .text(@x.tick_format) yield(self) if block_given? end |
Instance Method Details
#dot(points, shape = "circle", color = "#000") ⇒ Object
Plotting points with shape and color
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/data/plotter.rb', line 45 def dot points, shape = "circle", color = "#000" # FIXME: dirty hack for instance_exec x = @x y = @y @vis.add(pv.Dot).data(points) .left(lambda {|d| x.scale(d[0])}) .bottom(lambda {|d| y.scale(d[1])}) .shape(shape) .stroke_style(color) end |
#line(points, color = "#000") ⇒ Object
Plotting line with color
61 62 63 64 65 66 67 68 69 |
# File 'lib/data/plotter.rb', line 61 def line points, color = "#000" x = @x y = @y @vis.add(pv.Line).data(points) .left(lambda {|d| x.scale(d[0])}) .bottom(lambda {|d| y.scale(d[1])}) .stroke_style(color) end |
#to_svg ⇒ String
Convert to svg
74 75 76 77 |
# File 'lib/data/plotter.rb', line 74 def to_svg @vis.render @vis.to_svg end |