Daru

ruby
code
analysis
Author

geeknees

Published

July 13, 2023

https://github.com/SciRuby/daru

To plot the graph, it is necessary to add gem ‘daru-view’.

It also requires adding gem ‘matrics’. After the PR below is merged, it will be resolved. https://github.com/SciRuby/daru/pull/541

require 'bundler/setup'
require 'daru'
true
df = Daru::DataFrame.new({
    Array.new(100) {|i| i},
    100.times.map{rand}
  })
  df.plot , , 
df = Daru::DataFrame.new({
     => [30.4, 23.5, 44.5, 20.3, 34, 24, 31.45, 28.34, 37, 24],
           => [350, 150, 500, 200, 480, 250, 330, 400, 420, 560],
            => ['Pune', 'Delhi']*5,
           => [15,20]*5
    })
  df
Daru::DataFrame(10x4)
temperature sales city staff
0 30.4 350 Pune 15
1 23.5 150 Delhi 20
2 44.5 500 Pune 15
3 20.3 200 Delhi 20
4 34 480 Pune 15
5 24 250 Delhi 20
6 31.45 330 Pune 15
7 28.34 400 Delhi 20
8 37 420 Pune 15
9 24 560 Delhi 20
df.plot(, , ) do |plot, diagram|
    plot.x_label "Temperature"
    plot.y_label "Sales"
    plot.yrange [100, 600]
    plot.xrange [15, 50]
    diagram.tooltip_contents([, ])
    diagram.color(Nyaplot::Colors.qual) # set the color scheme for this diagram. See Nyaplot::Colors for more info.
    diagram.fill_by() # Change color of each point WRT to the city that it belongs to.
    diagram.shape_by() # Shape each point WRT to the city that it belongs to.
  end