charty 0.1.4.dev → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +71 -0
  3. data/.github/workflows/nmatrix.yml +67 -0
  4. data/.github/workflows/pycall.yml +86 -0
  5. data/Dockerfile.dev +9 -1
  6. data/Gemfile +18 -0
  7. data/README.md +128 -9
  8. data/Rakefile +4 -5
  9. data/charty.gemspec +7 -2
  10. data/examples/Gemfile +1 -0
  11. data/examples/active_record.ipynb +34 -34
  12. data/examples/daru.ipynb +71 -29
  13. data/examples/iris_dataset.ipynb +12 -5
  14. data/examples/nmatrix.ipynb +30 -30
  15. data/examples/numo_narray.ipynb +245 -0
  16. data/examples/palette.rb +71 -0
  17. data/examples/sample.png +0 -0
  18. data/examples/sample_bokeh.ipynb +156 -0
  19. data/examples/sample_google_chart.ipynb +229 -68
  20. data/examples/sample_gruff.ipynb +148 -133
  21. data/examples/sample_images/bar_bokeh.html +85 -0
  22. data/examples/sample_images/barh_bokeh.html +85 -0
  23. data/examples/sample_images/barh_gruff.png +0 -0
  24. data/examples/sample_images/box_plot_bokeh.html +85 -0
  25. data/examples/sample_images/{boxplot_pyplot.png → box_plot_pyplot.png} +0 -0
  26. data/examples/sample_images/curve_bokeh.html +85 -0
  27. data/examples/sample_images/curve_with_function_bokeh.html +85 -0
  28. data/examples/sample_images/{errorbar_pyplot.png → error_bar_pyplot.png} +0 -0
  29. data/examples/sample_images/hist_gruff.png +0 -0
  30. data/examples/sample_images/scatter_bokeh.html +85 -0
  31. data/examples/sample_pyplot.ipynb +37 -35
  32. data/images/penguins_body_mass_g_flipper_length_mm_scatter_plot.png +0 -0
  33. data/images/penguins_body_mass_g_flipper_length_mm_species_scatter_plot.png +0 -0
  34. data/images/penguins_body_mass_g_flipper_length_mm_species_sex_scatter_plot.png +0 -0
  35. data/images/penguins_species_body_mass_g_bar_plot_h.png +0 -0
  36. data/images/penguins_species_body_mass_g_bar_plot_v.png +0 -0
  37. data/images/penguins_species_body_mass_g_box_plot_h.png +0 -0
  38. data/images/penguins_species_body_mass_g_box_plot_v.png +0 -0
  39. data/images/penguins_species_body_mass_g_sex_bar_plot_v.png +0 -0
  40. data/images/penguins_species_body_mass_g_sex_box_plot_v.png +0 -0
  41. data/lib/charty.rb +13 -7
  42. data/lib/charty/backend_methods.rb +8 -0
  43. data/lib/charty/backends.rb +80 -0
  44. data/lib/charty/backends/bokeh.rb +80 -0
  45. data/lib/charty/backends/google_charts.rb +267 -0
  46. data/lib/charty/backends/gruff.rb +104 -67
  47. data/lib/charty/backends/plotly.rb +549 -0
  48. data/lib/charty/backends/pyplot.rb +584 -86
  49. data/lib/charty/backends/rubyplot.rb +82 -74
  50. data/lib/charty/backends/unicode_plot.rb +79 -0
  51. data/lib/charty/index.rb +213 -0
  52. data/lib/charty/linspace.rb +1 -1
  53. data/lib/charty/missing_value_support.rb +14 -0
  54. data/lib/charty/plot_methods.rb +184 -0
  55. data/lib/charty/plotter.rb +57 -41
  56. data/lib/charty/plotters.rb +11 -0
  57. data/lib/charty/plotters/abstract_plotter.rb +156 -0
  58. data/lib/charty/plotters/bar_plotter.rb +216 -0
  59. data/lib/charty/plotters/box_plotter.rb +94 -0
  60. data/lib/charty/plotters/categorical_plotter.rb +380 -0
  61. data/lib/charty/plotters/count_plotter.rb +7 -0
  62. data/lib/charty/plotters/estimation_support.rb +84 -0
  63. data/lib/charty/plotters/random_support.rb +25 -0
  64. data/lib/charty/plotters/relational_plotter.rb +518 -0
  65. data/lib/charty/plotters/scatter_plotter.rb +115 -0
  66. data/lib/charty/plotters/vector_plotter.rb +6 -0
  67. data/lib/charty/statistics.rb +114 -0
  68. data/lib/charty/table.rb +82 -3
  69. data/lib/charty/table_adapters.rb +25 -0
  70. data/lib/charty/table_adapters/active_record_adapter.rb +63 -0
  71. data/lib/charty/table_adapters/base_adapter.rb +69 -0
  72. data/lib/charty/table_adapters/daru_adapter.rb +70 -0
  73. data/lib/charty/table_adapters/datasets_adapter.rb +49 -0
  74. data/lib/charty/table_adapters/hash_adapter.rb +224 -0
  75. data/lib/charty/table_adapters/narray_adapter.rb +76 -0
  76. data/lib/charty/table_adapters/nmatrix_adapter.rb +67 -0
  77. data/lib/charty/table_adapters/pandas_adapter.rb +81 -0
  78. data/lib/charty/vector.rb +69 -0
  79. data/lib/charty/vector_adapters.rb +183 -0
  80. data/lib/charty/vector_adapters/array_adapter.rb +109 -0
  81. data/lib/charty/vector_adapters/daru_adapter.rb +171 -0
  82. data/lib/charty/vector_adapters/narray_adapter.rb +187 -0
  83. data/lib/charty/vector_adapters/nmatrix_adapter.rb +37 -0
  84. data/lib/charty/vector_adapters/numpy_adapter.rb +168 -0
  85. data/lib/charty/vector_adapters/pandas_adapter.rb +200 -0
  86. data/lib/charty/version.rb +1 -1
  87. metadata +127 -13
  88. data/.travis.yml +0 -11
  89. data/examples/numo-narray.ipynb +0 -234
  90. data/lib/charty/backends/google_chart.rb +0 -167
  91. data/lib/charty/plotter_adapter.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac0ecbfb31a75423c412a90df4e17bb155485a0cec9cc9cea06b93d92759ae57
4
- data.tar.gz: 75010b133927cfc7e7a028b3b0abf9424aa1138b268712375a76a2cd1c5149bf
3
+ metadata.gz: 6d70645a4ca621ee142714f3079e85dc843585fa6364c4476d4fdd86761c3b6f
4
+ data.tar.gz: b4fa589a9b2c5ba31a6869399c5e90e79767d9e8e4a9a0bf0c5e2d4997725dbf
5
5
  SHA512:
6
- metadata.gz: 2c2d710b65fccbf44338f3f42780130ad55ecff5a86a908664bfa448438d77ecd78e493b1c3a3d4ab30e53b2b4125096cf5784bf77d0df6cde2a11454efbde29
7
- data.tar.gz: bed880d3aee1c5d6bd16b2ab30d4ea877cf4ede53609d100703042aefc6f2376adb0df188fb8f11a648ed6343f8c434664c715dd9b08b1a7b57693715995ce36
6
+ metadata.gz: 6588c1c0105d0994cd024d08f328a6bf10241975abf4ee1b332be0a956f32d7073aed9867b5ddf708ef578e570caf733d422153a479ecae6fedef81daab391c1
7
+ data.tar.gz: 47999e4ce59f7cfb4263a5002b3dc070c128971257d7fed81fc23bd7314632cd441bba2ac93a0fdbeb3644d739434dad3d1cad7b465a093af6c53a5766555991
@@ -0,0 +1,71 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ types:
9
+ - opened
10
+ - synchronize
11
+ - reopened
12
+
13
+ jobs:
14
+ test:
15
+ name: ${{ matrix.os }}/${{ matrix.ruby }}
16
+ runs-on: ${{ matrix.os }}
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ os:
21
+ - ubuntu-20.04
22
+ - ubuntu-18.04
23
+ ruby:
24
+ - "3.0"
25
+ - 2.7
26
+ - 2.6
27
+ include:
28
+ - { os: ubuntu-20.04 , ruby: head }
29
+
30
+ steps:
31
+ - uses: actions/checkout@v2
32
+
33
+ - name: Set up Ruby
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby }}
37
+
38
+ - uses: actions/cache@v2
39
+ if: runner.os == 'Linux'
40
+ with:
41
+ path: ~/.cache/red-datasets
42
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
43
+ restore-keys: ${{ runner.os }}-
44
+
45
+ - uses: actions/cache@v2
46
+ if: |
47
+ runner.os == 'macOS'
48
+ with:
49
+ path: |
50
+ ~/Library/Caches/red-datasets
51
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
52
+ restore-keys: ${{ runner.os }}-
53
+
54
+ - uses: actions/cache@v2
55
+ if: |
56
+ runner.os == 'Windows'
57
+ with:
58
+ path: |
59
+ ~/AppData/red-datasets
60
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
61
+ restore-keys: ${{ runner.os }}-
62
+
63
+ - run: sudo apt install build-essential libsqlite3-dev
64
+
65
+ - run: bundle install --jobs 4 --retry 3 --without "nmatrix python"
66
+
67
+ - run: bundle exec rake
68
+
69
+ - run: rake build
70
+
71
+ - run: gem install --user pkg/*.gem
@@ -0,0 +1,67 @@
1
+ name: CI with NMatrix
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ types:
9
+ - opened
10
+ - synchronize
11
+ - reopened
12
+
13
+ jobs:
14
+ test:
15
+ name: ${{ matrix.os }}/${{ matrix.ruby }}
16
+ runs-on: ${{ matrix.os }}
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ os:
21
+ - ubuntu-20.04
22
+ ruby:
23
+ - 2.7
24
+ - 2.6
25
+
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+
29
+ - name: Set up Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby }}
33
+
34
+ - uses: actions/cache@v2
35
+ if: runner.os == 'Linux'
36
+ with:
37
+ path: ~/.cache/red-datasets
38
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
39
+ restore-keys: ${{ runner.os }}-
40
+
41
+ - uses: actions/cache@v2
42
+ if: |
43
+ runner.os == 'macOS'
44
+ with:
45
+ path: |
46
+ ~/Library/Caches/red-datasets
47
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
48
+ restore-keys: ${{ runner.os }}-
49
+
50
+ - uses: actions/cache@v2
51
+ if: |
52
+ runner.os == 'Windows'
53
+ with:
54
+ path: |
55
+ ~/AppData/red-datasets
56
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
57
+ restore-keys: ${{ runner.os }}-
58
+
59
+ - run: sudo apt install build-essential libsqlite3-dev
60
+
61
+ - run: bundle install --jobs 4 --retry 3 --without "numo python"
62
+
63
+ - run: bundle exec rake
64
+
65
+ - run: rake build
66
+
67
+ - run: gem install --user pkg/*.gem
@@ -0,0 +1,86 @@
1
+ name: CI with matplotlib and pandas
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ types:
9
+ - opened
10
+ - synchronize
11
+ - reopened
12
+
13
+ jobs:
14
+ test:
15
+ name: ${{ matrix.os }}/${{ matrix.ruby }}/${{ matrix.python }}-${{ matrix.python_architecture }}
16
+ runs-on: ${{ matrix.os }}
17
+
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ os:
22
+ - ubuntu-20.04
23
+ - ubuntu-18.04
24
+ ruby:
25
+ - "3.0"
26
+ - 2.7
27
+ - 2.6
28
+ python:
29
+ - 3.x
30
+ - 2.x
31
+ python_architecture:
32
+ - x64
33
+ include:
34
+ - { os: ubuntu-20.04 , ruby: head , python: 3.x , python_architecture: x64 }
35
+
36
+ steps:
37
+ - uses: actions/checkout@v2
38
+
39
+ - name: Setup Ruby
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby }}
43
+
44
+ - name: Setup Python
45
+ uses: actions/setup-python@v2
46
+ with:
47
+ python-version: ${{ matrix.python }}
48
+ architecture: ${{ matrix.python_architecture }}
49
+
50
+ - uses: actions/cache@v2
51
+ if: runner.os == 'Linux'
52
+ with:
53
+ path: ~/.cache/red-datasets
54
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
55
+ restore-keys: ${{ runner.os }}-
56
+
57
+ - uses: actions/cache@v2
58
+ if: |
59
+ runner.os == 'macOS'
60
+ with:
61
+ path: |
62
+ ~/Library/Caches/red-datasets
63
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
64
+ restore-keys: ${{ runner.os }}-
65
+
66
+ - uses: actions/cache@v2
67
+ if: |
68
+ runner.os == 'Windows'
69
+ with:
70
+ path: |
71
+ ~/AppData/red-datasets
72
+ key: ${{ runner.os }}-${{ hashFiles('lib/**') }}
73
+ restore-keys: ${{ runner.os }}-
74
+
75
+ - run: sudo apt install build-essential libsqlite3-dev
76
+
77
+ - run: pip install --user matplotlib pandas
78
+
79
+ - run: bundle install --jobs 4 --retry 3 --without "nmatrix numo"
80
+
81
+ - run: python -V
82
+
83
+ - run: bundle exec rake
84
+ env:
85
+ PYTHON: python
86
+ continue-on-error: ${{ matrix.python == '2.x' }}
data/Dockerfile.dev CHANGED
@@ -1,2 +1,10 @@
1
- ARG BASE_IMAGE_TAG=c9ca70040856
1
+ ARG BASE_IMAGE_TAG=e1a22a2
2
2
  FROM rubydata/minimal-notebook:$BASE_IMAGE_TAG
3
+
4
+ USER root
5
+ RUN mkdir -p /charty && \
6
+ chown ${NB_USER}:users /charty
7
+
8
+ USER ${NB_USER}
9
+
10
+ WORKDIR /charty
data/Gemfile CHANGED
@@ -4,3 +4,21 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in charty.gemspec
6
6
  gemspec
7
+
8
+ group :cruby do
9
+ gem "enumerable-statistics"
10
+ end
11
+
12
+ group :nmatrix do
13
+ gem "nmatrix"
14
+ end
15
+
16
+ group :numo do
17
+ gem "numo-narray"
18
+ end
19
+
20
+ group :python do
21
+ gem "matplotlib"
22
+ gem "numpy"
23
+ gem "pandas"
24
+ end
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Charty - Visualizing your data in Ruby
2
2
 
3
- [![Build Status](https://travis-ci.org/red-data-tools/charty.svg?branch=master)](https://travis-ci.org/red-data-tools/charty)
3
+ ![Build Status](https://github.com/red-data-tools/charty/workflows/CI/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/charty.svg)](https://badge.fury.io/rb/charty)
4
5
  [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/red-data-tools/charty/master?filepath=iris_dataset.ipynb)
6
+ [![Docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/charty)
5
7
 
6
8
  Charty is open-source Ruby library for visualizing your data in a simple way.
7
9
  In Charty, you need to write very few lines of code for representing what you want to do.
@@ -32,8 +34,8 @@ $ CONFIGURE_OPTS="--enable-shared" pyenv install 3.x.x
32
34
  ### With Matplotlib
33
35
 
34
36
  ```
35
- sudo gem install charty --pre
36
- sudo gem install matplotlib
37
+ gem install charty --pre
38
+ gem install matplotlib
37
39
  sudo apt install python3-pip
38
40
  sudo python3 -m pip install -U pip matplotlib
39
41
  ```
@@ -43,18 +45,135 @@ sudo python3 -m pip install -U pip matplotlib
43
45
  e.g.
44
46
 
45
47
  ```
46
- $ bundle install
47
- $ docker build -f ./Dockerfile.dev -t charty-dev:0.1 .
48
- $ docker run -it -v ${PWD}:/charty -w /charty charty-dev:0.1 ./bin/console
48
+ $ docker build -f ./Dockerfile.dev -t charty-dev:latest .
49
+ $ docker run --rm -v $(pwd):/charty charty-dev:latest bundle install
50
+ $ docker run --rm -it -v $(pwd):/charty charty-dev:latest ./bin/console
49
51
  irb(main):001:0> Charty::VERSION
50
- => "0.1.4-dev"
52
+ => "0.2.2"
51
53
 
52
54
  # When using jupyter notebook
53
- $ docker run -it -v ${PWD}:/charty -w /charty -p 8888:8888 charty-dev:0.1
55
+ $ docker run --rm -it -v $(pwd):/charty -p 8888:8888 charty-dev:latest
54
56
  ```
55
57
 
56
58
  ## Usage
57
59
 
60
+ ### Statistical plotting interface
61
+
62
+ Charty supports statistical plotting as Python's seaborn.
63
+
64
+ In the following examplles, we use the `penguins` dataset provided in red-datasets.
65
+
66
+ ```ruby
67
+ require "datasets"
68
+
69
+ penguins = Datasets::Penguins.new
70
+ ```
71
+
72
+ #### Bar plot
73
+
74
+ Charty's statistical bar plot shows the relationship between a categorical variable and estimated means of a numeric variable.
75
+ This plot automatically calculates mean estimation and its 95% confidence interval of the numeric variable.
76
+
77
+ When we specify the categorical varaible as x-axis, the plot draws a vertical bar chart.
78
+ Instead, when we specify the categorical variable as y-axis, the plot draws a horizontal bar chart.
79
+
80
+ The following code shows the relationship between species and the mean body masses of penguins in a vertical bar chart.
81
+
82
+ ```ruby
83
+ Charty::Backends.use(:pyplot)
84
+ Charty.bar_plot(data: penguins, x: :species, y: :body_mass_g).render
85
+ ```
86
+
87
+ ![](images/penguins_species_body_mass_g_bar_plot_v.png)
88
+
89
+ Exchanging x and y axes alternates the orientation of the resulting chart.
90
+
91
+ ```ruby
92
+ Charty::Backends.use(:pyplot)
93
+ Charty.bar_plot(data: penguins, x: :body_mass_g, y: :species).render
94
+ ```
95
+
96
+ ![](images/penguins_species_body_mass_g_bar_plot_h.png)
97
+
98
+ Adding color axis introduces color grouping in the bar plot.
99
+
100
+ ```ruby
101
+ Charty::Backends.use(:pyplot)
102
+ Charty.bar_plot(data: penguins, x: :species, y: :body_mass_g, color: :sex).render
103
+ ```
104
+
105
+ ![](images/penguins_species_body_mass_g_sex_bar_plot_v.png)
106
+
107
+ #### Box plot
108
+
109
+ Charty's statistical box plot shows distributions of a numeric variable per categories.
110
+ The distributions are showed by boxes with whiskers that characterized by five-number summary.
111
+ This plot automatically calculates five-number summary the numeric variable per categories.
112
+
113
+ When we specify the categorical varaible as x-axis, the plot draws a vertical box plot chart.
114
+ Instead, when we specify the categorical variable as y-axis, the plot draws a horizontal box plot chart.
115
+
116
+ The following code draws a vertical box plot to show distributions of penguins' body mass per species.
117
+
118
+ ```ruby
119
+ Charty::Backends.use(:pyplot)
120
+ Charty.box_plot(data: penguins, x: :species, y: :body_mass_g).render
121
+ ```
122
+
123
+ ![](images/penguins_species_body_mass_g_box_plot_v.png)
124
+
125
+ As `bar_plot` above, exchanging x and y axes alternates the orientation of the resulting chart.
126
+
127
+ ```ruby
128
+ Charty::Backends.use(:pyplot)
129
+ Charty.box_plot(data: penguins, x: :body_mass_g, y: :species).render
130
+ ```
131
+
132
+ ![](images/penguins_species_body_mass_g_box_plot_h.png)
133
+
134
+ Adding color axis introduces color grouping in the box plot.
135
+
136
+ ```ruby
137
+ Charty::Backends.use(:pyplot)
138
+ Charty.box_plot(data: penguins, x: :species, y: :body_mass_g, color: :sex).render
139
+ ```
140
+
141
+ ![](images/penguins_species_body_mass_g_sex_box_plot_v.png)
142
+
143
+ #### Scatter plot
144
+
145
+ Charty's scatter plot shows the relationship between two numeric variables.
146
+
147
+ ```ruby
148
+ Charty::Backends.use(:pyplot)
149
+ Charty.scatter_plot(data: penguins, x: :body_mass_g, y: flipper_length_mm)
150
+ ```
151
+
152
+ ![](images/penguins_body_mass_g_flipper_length_mm_scatter_plot.png)
153
+
154
+ Adding color axis introduces color grouping in the scatter plot.
155
+ The following example specifies `:species` variable in the color axis.
156
+ It shows the different species by the different colors.
157
+
158
+ ```ruby
159
+ Charty::Backends.use(:pyplot)
160
+ Charty.scatter_plot(data: penguins, x: :body_mass_g, y: flipper_length_mm, color: :species)
161
+ ```
162
+
163
+ ![](images/penguins_body_mass_g_flipper_length_mm_species_scatter_plot.png)
164
+
165
+ Moreover, size and style axes can be specified.
166
+ The following example specifies `:sex` variable in the style axis.
167
+
168
+ ```ruby
169
+ Charty::Backends.use(:pyplot)
170
+ Charty.scatter_plot(data: penguins, x: :body_mass_g, y: flipper_length_mm, color: :species, style: :sex)
171
+ ```
172
+
173
+ ![](images/penguins_body_mass_g_flipper_length_mm_species_sex_scatter_plot.png)
174
+
175
+ ### Old-style plotting interface
176
+
58
177
  ```ruby
59
178
  require 'charty'
60
179
  charty = Charty::Plotter.new(:pyplot)
@@ -354,7 +473,7 @@ hist.render("sample_images/hist_pyplot.png")
354
473
 
355
474
  #### Gruff
356
475
 
357
- Not supported
476
+ ![hist_gruff](https://raw.githubusercontent.com/red-data-tools/charty/master/examples/sample_images/hist_gruff.png)
358
477
 
359
478
  #### Rubyplot
360
479
 
data/Rakefile CHANGED
@@ -1,10 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
4
+ desc "Run tests"
5
+ task :test do
6
+ ruby("test/run.rb")
8
7
  end
9
8
 
10
- task :default => :test
9
+ task default: :test