IRubyでシュッとグラフを書く

rbplotly

In [1]:
require 'rbplotly'
Out[1]:
true
In [2]:
trace1 = { x: [1,2,3,4,5,6], y: [100,200,300,400,500,600] }
trace2 = { x: [1,2,3,4,5,6], y: [600,500,400,300,200,100] }
traces = [trace1, trace2]
pl = Plotly::Plot.new(data: traces)
pl.show
Out[2]:
#<CZTop::Socket::PUB:0x7f8bc18b0030 last_endpoint="tcp://127.0.0.1:59691">

daru

In [3]:
require 'daru'

df = Daru::DataFrame.from_csv('O_TUKIBETSU_NENREI.csv')
Out[3]:
Daru::DataFrame(106x6)
year month age male female total_count
0 2017 5 0 426 457 883
1 2017 5 1 462 444 906
2 2017 5 2 509 468 977
3 2017 5 3 499 446 945
4 2017 5 4 505 428 933
5 2017 5 5 481 469 950
6 2017 5 6 533 494 1027
7 2017 5 7 517 456 973
8 2017 5 8 539 503 1042
9 2017 5 9 519 526 1045
10 2017 5 10 538 523 1061
11 2017 5 11 546 520 1066
12 2017 5 12 561 520 1081
13 2017 5 13 609 553 1162
14 2017 5 14 576 570 1146
15 2017 5 15 643 616 1259
16 2017 5 16 623 628 1251
17 2017 5 17 640 680 1320
18 2017 5 18 635 578 1213
19 2017 5 19 515 570 1085
20 2017 5 20 572 561 1133
21 2017 5 21 537 528 1065
22 2017 5 22 552 538 1090
23 2017 5 23 499 510 1009
24 2017 5 24 549 515 1064
25 2017 5 25 565 527 1092
26 2017 5 26 565 513 1078
27 2017 5 27 589 573 1162
28 2017 5 28 611 594 1205
29 2017 5 29 627 617 1244
... ... ... ... ... ... ...
105 2017 5 105 1 1 2

daru-plotly

In [4]:
require 'daru/plotly'

include Daru::Plotly::Methods

plot(df, x: 'age', y: 'total_count').show
Out[4]:
#<CZTop::Socket::PUB:0x7f8bc18b0030 last_endpoint="tcp://127.0.0.1:59691">
In [5]:
plot(df, x: 'age', y: ['total_count', 'male', 'female']).show
Out[5]:
#<CZTop::Socket::PUB:0x7f8bc18b0030 last_endpoint="tcp://127.0.0.1:59691">