charty 0.2.3 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +56 -23
- data/.github/workflows/nmatrix.yml +67 -0
- data/.github/workflows/pycall.yml +86 -0
- data/Gemfile +18 -0
- data/README.md +172 -4
- data/Rakefile +4 -5
- data/charty.gemspec +10 -6
- data/examples/sample_images/hist_gruff.png +0 -0
- data/images/penguins_body_mass_g_flipper_length_mm_scatter_plot.png +0 -0
- data/images/penguins_body_mass_g_flipper_length_mm_species_scatter_plot.png +0 -0
- data/images/penguins_body_mass_g_flipper_length_mm_species_sex_scatter_plot.png +0 -0
- data/images/penguins_species_body_mass_g_bar_plot_h.png +0 -0
- data/images/penguins_species_body_mass_g_bar_plot_v.png +0 -0
- data/images/penguins_species_body_mass_g_box_plot_h.png +0 -0
- data/images/penguins_species_body_mass_g_box_plot_v.png +0 -0
- data/images/penguins_species_body_mass_g_sex_bar_plot_v.png +0 -0
- data/images/penguins_species_body_mass_g_sex_box_plot_v.png +0 -0
- data/lib/charty.rb +8 -1
- data/lib/charty/backends/bokeh.rb +2 -2
- data/lib/charty/backends/google_charts.rb +1 -1
- data/lib/charty/backends/gruff.rb +14 -3
- data/lib/charty/backends/plotly.rb +731 -32
- data/lib/charty/backends/plotly_helpers/html_renderer.rb +203 -0
- data/lib/charty/backends/plotly_helpers/notebook_renderer.rb +87 -0
- data/lib/charty/backends/plotly_helpers/plotly_renderer.rb +121 -0
- data/lib/charty/backends/pyplot.rb +514 -66
- data/lib/charty/backends/rubyplot.rb +1 -1
- data/lib/charty/cache_dir.rb +27 -0
- data/lib/charty/dash_pattern_generator.rb +57 -0
- data/lib/charty/index.rb +213 -0
- data/lib/charty/iruby_helper.rb +18 -0
- data/lib/charty/linspace.rb +1 -1
- data/lib/charty/plot_methods.rb +283 -8
- data/lib/charty/plotter.rb +2 -2
- data/lib/charty/plotters.rb +11 -0
- data/lib/charty/plotters/abstract_plotter.rb +186 -16
- data/lib/charty/plotters/bar_plotter.rb +189 -7
- data/lib/charty/plotters/box_plotter.rb +64 -11
- data/lib/charty/plotters/categorical_plotter.rb +272 -40
- data/lib/charty/plotters/count_plotter.rb +7 -0
- data/lib/charty/plotters/distribution_plotter.rb +143 -0
- data/lib/charty/plotters/estimation_support.rb +84 -0
- data/lib/charty/plotters/histogram_plotter.rb +186 -0
- data/lib/charty/plotters/line_plotter.rb +300 -0
- data/lib/charty/plotters/random_support.rb +25 -0
- data/lib/charty/plotters/relational_plotter.rb +635 -0
- data/lib/charty/plotters/scatter_plotter.rb +80 -0
- data/lib/charty/plotters/vector_plotter.rb +6 -0
- data/lib/charty/statistics.rb +96 -2
- data/lib/charty/table.rb +160 -15
- data/lib/charty/table_adapters.rb +2 -0
- data/lib/charty/table_adapters/active_record_adapter.rb +17 -9
- data/lib/charty/table_adapters/base_adapter.rb +166 -0
- data/lib/charty/table_adapters/daru_adapter.rb +39 -3
- data/lib/charty/table_adapters/datasets_adapter.rb +13 -2
- data/lib/charty/table_adapters/hash_adapter.rb +141 -16
- data/lib/charty/table_adapters/narray_adapter.rb +25 -6
- data/lib/charty/table_adapters/nmatrix_adapter.rb +15 -5
- data/lib/charty/table_adapters/pandas_adapter.rb +163 -0
- data/lib/charty/util.rb +28 -0
- data/lib/charty/vector.rb +69 -0
- data/lib/charty/vector_adapters.rb +187 -0
- data/lib/charty/vector_adapters/array_adapter.rb +101 -0
- data/lib/charty/vector_adapters/daru_adapter.rb +163 -0
- data/lib/charty/vector_adapters/narray_adapter.rb +182 -0
- data/lib/charty/vector_adapters/nmatrix_adapter.rb +37 -0
- data/lib/charty/vector_adapters/numpy_adapter.rb +168 -0
- data/lib/charty/vector_adapters/pandas_adapter.rb +199 -0
- data/lib/charty/version.rb +1 -1
- metadata +92 -25
@@ -0,0 +1,27 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module Charty
|
4
|
+
module CacheDir
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def cache_dir_path
|
8
|
+
platform_cache_dir_path + "charty"
|
9
|
+
end
|
10
|
+
|
11
|
+
def platform_cache_dir_path
|
12
|
+
base_dir = case RUBY_PLATFORM
|
13
|
+
when /mswin/, /mingw/
|
14
|
+
ENV.fetch("LOCALAPPDATA", "~/AppData/Local")
|
15
|
+
when /darwin/
|
16
|
+
"~/Library/Caches"
|
17
|
+
else
|
18
|
+
ENV.fetch("XDG_CACHE_HOME", "~/.cache")
|
19
|
+
end
|
20
|
+
Pathname(base_dir).expand_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def path(*path_components)
|
24
|
+
cache_dir_path.join(*path_components)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Charty
|
2
|
+
module DashPatternGenerator
|
3
|
+
NAMED_PATTERNS = {
|
4
|
+
solid: "",
|
5
|
+
dash: [4, 1.5],
|
6
|
+
dot: [1, 1],
|
7
|
+
dashdot: [3, 1.25, 1.5, 1.25],
|
8
|
+
longdashdot: [5, 1, 1, 1],
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def self.valid_name?(name)
|
12
|
+
name = case name
|
13
|
+
when Symbol, String
|
14
|
+
name.to_sym
|
15
|
+
else
|
16
|
+
name.to_str.to_sym
|
17
|
+
end
|
18
|
+
NAMED_PATTERNS.key?(name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.pattern_to_name(pattern)
|
22
|
+
NAMED_PATTERNS.each do |key, val|
|
23
|
+
return key if pattern == val
|
24
|
+
end
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.each
|
29
|
+
return enum_for(__method__) unless block_given?
|
30
|
+
|
31
|
+
NAMED_PATTERNS.each_value do |pattern|
|
32
|
+
yield pattern
|
33
|
+
end
|
34
|
+
|
35
|
+
m = 3
|
36
|
+
while true
|
37
|
+
# Long and short dash combinations
|
38
|
+
a = [3, 1.25].repeated_combination(m).to_a[1..-2].reverse
|
39
|
+
b = [4, 1].repeated_combination(m).to_a[1..-2]
|
40
|
+
|
41
|
+
# Interleave these combinations
|
42
|
+
segment_list = a.zip(b).flatten(1)
|
43
|
+
|
44
|
+
# Insert the gaps
|
45
|
+
segment_list.each do |segment|
|
46
|
+
gap = segment.min
|
47
|
+
pattern = segment.map {|seg| [seg, gap] }.flatten
|
48
|
+
yield pattern
|
49
|
+
end
|
50
|
+
|
51
|
+
m += 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
extend Enumerable
|
56
|
+
end
|
57
|
+
end
|
data/lib/charty/index.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module Charty
|
4
|
+
class Index
|
5
|
+
extend Forwardable
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def initialize(values, name: nil)
|
9
|
+
@values = values
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :values
|
14
|
+
attr_accessor :name
|
15
|
+
|
16
|
+
def_delegators :values, :length, :size, :each, :to_a
|
17
|
+
|
18
|
+
def ==(other)
|
19
|
+
case other
|
20
|
+
when DaruIndex, PandasIndex
|
21
|
+
return false if length != other.length
|
22
|
+
to_a == other.to_a
|
23
|
+
when Index
|
24
|
+
return false if length != other.length
|
25
|
+
return true if values == other.values
|
26
|
+
to_a == other.to_a
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](i)
|
33
|
+
case i
|
34
|
+
when 0 ... length
|
35
|
+
values[i]
|
36
|
+
else
|
37
|
+
raise IndexError, "index out of range"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def loc(key)
|
42
|
+
values.index(key)
|
43
|
+
end
|
44
|
+
|
45
|
+
def union(other)
|
46
|
+
case other
|
47
|
+
when PandasIndex
|
48
|
+
index = PandasIndex.try_convert(self)
|
49
|
+
return index.union(other) if index
|
50
|
+
end
|
51
|
+
|
52
|
+
Index.new(to_a.union(other.to_a), name: name)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class RangeIndex < Index
|
57
|
+
def initialize(values, name: nil)
|
58
|
+
if values.is_a?(Range) && values.begin.is_a?(Integer) && values.end.is_a?(Integer)
|
59
|
+
super
|
60
|
+
else
|
61
|
+
raise ArgumentError, "values must be an integer range"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def length
|
66
|
+
size
|
67
|
+
end
|
68
|
+
|
69
|
+
def [](i)
|
70
|
+
case i
|
71
|
+
when 0 ... length
|
72
|
+
values.begin + i
|
73
|
+
else
|
74
|
+
raise IndexError, "index out of range (#{i} for 0 ... #{length})"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def loc(key)
|
79
|
+
case key
|
80
|
+
when Integer
|
81
|
+
if values.cover?(key)
|
82
|
+
return key - values.begin
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def union(other)
|
88
|
+
case other
|
89
|
+
when RangeIndex
|
90
|
+
return union(other.values)
|
91
|
+
when Range
|
92
|
+
if disjoint_range?(values, other)
|
93
|
+
return Index.new(values.to_a.union(other.to_a))
|
94
|
+
end
|
95
|
+
new_beg = [values.begin, other.begin].min
|
96
|
+
new_end = [values.end, other.end ].max
|
97
|
+
new_range = if values.end < new_end
|
98
|
+
if other.exclude_end?
|
99
|
+
new_beg ... new_end
|
100
|
+
else
|
101
|
+
new_beg .. new_end
|
102
|
+
end
|
103
|
+
elsif other.end < new_end
|
104
|
+
if values.exclude_end?
|
105
|
+
new_beg ... new_end
|
106
|
+
else
|
107
|
+
new_beg .. new_end
|
108
|
+
end
|
109
|
+
else
|
110
|
+
if values.exclude_end? && other.exclude_end?
|
111
|
+
new_beg ... new_end
|
112
|
+
else
|
113
|
+
new_beg .. new_end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
RangeIndex.new(new_range)
|
117
|
+
else
|
118
|
+
super
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
private def disjoint_range?(r1, r2)
|
123
|
+
r1.end < r2.begin || r2.end < r1.begin
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class DaruIndex < Index
|
128
|
+
def_delegators :values, :name, :name=
|
129
|
+
|
130
|
+
def length
|
131
|
+
size
|
132
|
+
end
|
133
|
+
|
134
|
+
def ==(other)
|
135
|
+
case other
|
136
|
+
when DaruIndex
|
137
|
+
values == other.values
|
138
|
+
else
|
139
|
+
super
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class PandasIndex < Index
|
145
|
+
def self.try_convert(obj)
|
146
|
+
case obj
|
147
|
+
when PandasIndex
|
148
|
+
obj
|
149
|
+
when ->(x) { defined?(Pandas) && x.is_a?(Pandas::Index) }
|
150
|
+
PandasIndex.new(obj)
|
151
|
+
when RangeIndex, Range
|
152
|
+
obj = obj.values if obj.is_a?(RangeIndex)
|
153
|
+
stop = if obj.exclude_end?
|
154
|
+
obj.end
|
155
|
+
else
|
156
|
+
obj.end + 1
|
157
|
+
end
|
158
|
+
PandasIndex.new(Pandas.RangeIndex.new(obj.begin, stop))
|
159
|
+
when ->(x) { defined?(Enumerator::ArithmeticSequence) && x.is_a?(Enumerator::ArithmeticSequence) }
|
160
|
+
stop = if obj.exclude_end?
|
161
|
+
obj.end
|
162
|
+
else
|
163
|
+
obj.end + 1
|
164
|
+
end
|
165
|
+
PandasIndex.new(Pandas::RangeIndex.new(obj.begin, stop, obj.step))
|
166
|
+
when Index, Array, DaruIndex, ->(x) { defined?(Daru) && x.is_a?(Daru::Index) }
|
167
|
+
obj = obj.values if obj.is_a?(Index)
|
168
|
+
PandasIndex.new(Pandas::Index.new(obj.to_a))
|
169
|
+
else
|
170
|
+
nil
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def_delegators :values, :name, :name=
|
175
|
+
|
176
|
+
def length
|
177
|
+
size
|
178
|
+
end
|
179
|
+
|
180
|
+
def ==(other)
|
181
|
+
case other
|
182
|
+
when PandasIndex
|
183
|
+
Numpy.all(values == other.values)
|
184
|
+
when Index
|
185
|
+
return false if length != other.length
|
186
|
+
Numpy.all(values == other.values.to_a)
|
187
|
+
else
|
188
|
+
super
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def each(&block)
|
193
|
+
return enum_for(__method__) unless block_given?
|
194
|
+
|
195
|
+
i, n = 0, length
|
196
|
+
while i < n
|
197
|
+
yield self[i]
|
198
|
+
i += 1
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def union(other)
|
203
|
+
other = PandasIndex.try_convert(other)
|
204
|
+
# NOTE: Using `sort=False` in pandas.Index#union does not produce pandas.RangeIndex.
|
205
|
+
# TODO: Reconsider to use `sort=True` here.
|
206
|
+
PandasIndex.new(values.union(other.values, sort: false))
|
207
|
+
end
|
208
|
+
|
209
|
+
private def arithmetic_sequence?(x)
|
210
|
+
defined?(Enumerator::ArithmeticSequence) && x.is_a?(Enumerator::ArithmeticSequence)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Charty
|
2
|
+
module IRubyHelper
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def iruby_notebook?
|
6
|
+
# TODO: This cannot distinguish notebook and console.
|
7
|
+
defined?(IRuby)
|
8
|
+
end
|
9
|
+
|
10
|
+
def vscode?
|
11
|
+
ENV.key?("VSCODE_PID")
|
12
|
+
end
|
13
|
+
|
14
|
+
def nteract?
|
15
|
+
ENV.key?("NTERACT_EXE")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/charty/linspace.rb
CHANGED
data/lib/charty/plot_methods.rb
CHANGED
@@ -2,16 +2,291 @@ module Charty
|
|
2
2
|
module PlotMethods
|
3
3
|
# Show the given data as rectangular bars.
|
4
4
|
#
|
5
|
-
# @param x
|
6
|
-
# @param y
|
7
|
-
# @param color
|
8
|
-
# @param data
|
9
|
-
|
10
|
-
|
5
|
+
# @param x x-dimension input for plotting long-form data.
|
6
|
+
# @param y y-dimension input for plotting long-form data.
|
7
|
+
# @param color color-dimension input for plotting long-form data.
|
8
|
+
# @param data Dataset for plotting.
|
9
|
+
# @param order Order of the categorical dimension to plot the categorical levels in.
|
10
|
+
# @param color_order Order of the color dimension to plot the categorical levels in.
|
11
|
+
# @param estimator Statistical function to estimate withint each categorical bin.
|
12
|
+
# @param ci Size of confidence intervals to draw around estimated values.
|
13
|
+
# @param n_boot The size of bootstrap sample to use when computing confidence intervals.
|
14
|
+
# @param units Identifier of sampling unit.
|
15
|
+
# @param random Random seed or random number generator for reproducible bootstrapping.
|
16
|
+
# @param orient Orientation of the plot (:v for vertical, or :h for
|
17
|
+
# horizontal).
|
18
|
+
# @param key_color Color for all of the elements, or seed for a gradient palette.
|
19
|
+
# @param palette Colors to use for the different levels of the color-dimension variable.
|
20
|
+
# @param saturation Propotion of the original saturation to draw colors.
|
21
|
+
# @param error_color Color for the lines that represent the confidence intervals.
|
22
|
+
# @param error_width Thickness of error bar lines (and caps).
|
23
|
+
# @param cap_size Width of the caps on error bars.
|
24
|
+
# @param dodge [true,false] If true, bar position is shifted along the
|
25
|
+
# categorical axis for avoid overlapping when the color-dimension is used.
|
26
|
+
def bar_plot(x: nil, y: nil, color: nil, data: nil,
|
27
|
+
order: nil, color_order: nil,
|
28
|
+
estimator: :mean, ci: 95, n_boot: 1000, units: nil, random: nil,
|
29
|
+
orient: nil, key_color: nil, palette: nil, saturation: 1r,
|
30
|
+
error_color: [0.26, 0.26, 0.26], error_width: nil, cap_size: nil,
|
31
|
+
dodge: true, **options, &block)
|
32
|
+
Plotters::BarPlotter.new(
|
33
|
+
data: data, variables: { x: x, y: y, color: color },
|
34
|
+
order: order, orient: orient,
|
35
|
+
estimator: estimator, ci: ci, n_boot: n_boot, units: units, random: random,
|
36
|
+
color_order: color_order, key_color: key_color, palette: palette, saturation: saturation,
|
37
|
+
error_color: error_color, error_width: error_width, cap_size: cap_size,
|
38
|
+
dodge: dodge,
|
39
|
+
**options, &block
|
40
|
+
)
|
11
41
|
end
|
12
42
|
|
13
|
-
def
|
14
|
-
|
43
|
+
def count_plot(x: nil, y: nil, color: nil, data: nil,
|
44
|
+
order: nil, color_order: nil,
|
45
|
+
orient: nil, key_color: nil, palette: nil, saturation: 1r,
|
46
|
+
dodge: true, **options, &block)
|
47
|
+
case
|
48
|
+
when x.nil? && !y.nil?
|
49
|
+
x = y
|
50
|
+
orient = :h
|
51
|
+
when y.nil? && !x.nil?
|
52
|
+
y = x
|
53
|
+
orient = :v
|
54
|
+
when !x.nil? && !y.nil?
|
55
|
+
raise ArgumentError,
|
56
|
+
"Unable to pass both x and y to count_plot"
|
57
|
+
end
|
58
|
+
|
59
|
+
Plotters::CountPlotter.new(
|
60
|
+
data: data,
|
61
|
+
variables: { x: x, y: y, color: color },
|
62
|
+
order: order,
|
63
|
+
orient: orient,
|
64
|
+
estimator: :count,
|
65
|
+
ci: nil,
|
66
|
+
units: nil,
|
67
|
+
random: nil,
|
68
|
+
color_order: color_order,
|
69
|
+
key_color: key_color,
|
70
|
+
palette: palette,
|
71
|
+
saturation: saturation,
|
72
|
+
dodge: dodge,
|
73
|
+
**options
|
74
|
+
) do |plotter|
|
75
|
+
plotter.value_label = "count"
|
76
|
+
block.(plotter) unless block.nil?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Show the distributions of the given data by boxes and whiskers.
|
81
|
+
#
|
82
|
+
# @param x X-dimension input for plotting long-Form data.
|
83
|
+
# @param y Y-dimension input for plotting long-form data.
|
84
|
+
# @param color Color-dimension input for plotting long-form data.
|
85
|
+
# @param data Dataset for plotting.
|
86
|
+
# @param order Order of the categorical dimension to plot the categorical
|
87
|
+
# levels in.
|
88
|
+
# @param color_order Order of the color dimension to plot the categorical
|
89
|
+
# levels in.
|
90
|
+
# @param orient Orientation of the plot (:v for vertical, or :h for
|
91
|
+
# horizontal).
|
92
|
+
# @param key_color Color for all of the elements, or seed for a gradient
|
93
|
+
# palette.
|
94
|
+
# @param palette Colors to use for the different levels of the
|
95
|
+
# color-dimension variable.
|
96
|
+
# @param saturation Propotion of the original saturation to draw colors.
|
97
|
+
# @param width Width of a full element when not using the color-dimension,
|
98
|
+
# or width of all the elements for one level of the major grouping
|
99
|
+
# variable.
|
100
|
+
# @param dodge [true,false] If true, bar position is shifted along the
|
101
|
+
# categorical axis for avoid overlapping when the color-dimension
|
102
|
+
# is used.
|
103
|
+
# @param flier_size Size of the markers used to indicate outlier
|
104
|
+
# observations.
|
105
|
+
# @param line_width Width of the gray lines that frame the plot elements.
|
106
|
+
# @param whisker Propotion of the IQR past the low and high quartiles to
|
107
|
+
# extend the plot whiskers. Points outside of this range will be
|
108
|
+
# treated as outliers.
|
109
|
+
def box_plot(x: nil, y: nil, color: nil, data: nil,
|
110
|
+
order: nil, color_order: nil,
|
111
|
+
orient: nil, key_color: nil, palette: nil, saturation: 1r,
|
112
|
+
width: 0.8r, dodge: true, flier_size: 5, line_width: nil,
|
113
|
+
whisker: 1.5, **options, &block)
|
114
|
+
Plotters::BoxPlotter.new(
|
115
|
+
data: data,
|
116
|
+
variables: { x: x, y: y, color: color },
|
117
|
+
order: order,
|
118
|
+
color_order: color_order,
|
119
|
+
orient: orient,
|
120
|
+
key_color: key_color,
|
121
|
+
palette: palette,
|
122
|
+
saturation: saturation,
|
123
|
+
width: width,
|
124
|
+
dodge: dodge,
|
125
|
+
flier_size: flier_size,
|
126
|
+
line_width: line_width,
|
127
|
+
whisker: whisker,
|
128
|
+
**options,
|
129
|
+
&block
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Line plot
|
134
|
+
#
|
135
|
+
# @param x [vector-like object, key in data]
|
136
|
+
# @param y [vector-like object, key in data]
|
137
|
+
# @param color [vector-like object, key in data]
|
138
|
+
# @param style [vector-like object, key in data]
|
139
|
+
# @param size [vector-like object, key in data]
|
140
|
+
# @param data [table-like object]
|
141
|
+
# @param key_color [color object]
|
142
|
+
# @param palette [String,Array<Numeric>,Palette]
|
143
|
+
# @param color_order [Array<String>,Array<Symbol>]
|
144
|
+
# @param color_norm
|
145
|
+
# @param sizes [Array, Hash]
|
146
|
+
# @param size_order [Array]
|
147
|
+
# @param size_norm
|
148
|
+
# @param dashes [true, false, Array, Hash]
|
149
|
+
# @param markers [true, false, Array, Hash]
|
150
|
+
# @param style_order [Array]
|
151
|
+
# @param units [vector-like object, key in data]
|
152
|
+
# @param estimator [:mean]
|
153
|
+
# @param n_boot [Integer]
|
154
|
+
# @param random [Integer, Random, nil]
|
155
|
+
# @param sort [true, false]
|
156
|
+
# @param err_style [:band, :bars]
|
157
|
+
# @param err_params [Hash]
|
158
|
+
# @param error_bar
|
159
|
+
# @param x_scale [:linear, :log10]
|
160
|
+
# @param y_scale [:linear, :log10]
|
161
|
+
# @param legend [:auto, :brief, :full, false]
|
162
|
+
# How to draw legend. If :brief, numeric color and size variables
|
163
|
+
# will be represented with a sample of evenly spaced values. If
|
164
|
+
# :full, every group will get an entry in the legend. If :auto,
|
165
|
+
# choose between brief or full representation based on number of
|
166
|
+
# levels. If false, no legend data is added and no legend is drawn.
|
167
|
+
def line_plot(x: nil, y: nil, color: nil, style: nil, size: nil,
|
168
|
+
data: nil, key_color: nil, palette: nil, color_order: nil,
|
169
|
+
color_norm: nil, sizes: nil, size_order: nil, size_norm: nil,
|
170
|
+
markers: nil, dashes: true, style_order: nil,
|
171
|
+
units: nil, estimator: :mean, n_boot: 1000, random: nil,
|
172
|
+
sort: true, err_style: :band, err_params: nil, error_bar: [:ci, 95],
|
173
|
+
x_scale: :linear, y_scale: :linear, legend: :auto, **options, &block)
|
174
|
+
Plotters::LinePlotter.new(
|
175
|
+
data: data,
|
176
|
+
variables: { x: x, y: y, color: color, style: style, size: size },
|
177
|
+
key_color: key_color,
|
178
|
+
palette: palette,
|
179
|
+
color_order: color_order,
|
180
|
+
color_norm: color_norm,
|
181
|
+
sizes: sizes,
|
182
|
+
size_order: size_order,
|
183
|
+
size_norm: size_norm,
|
184
|
+
markers: markers,
|
185
|
+
dashes: dashes,
|
186
|
+
style_order: style_order,
|
187
|
+
units: units,
|
188
|
+
estimator: estimator,
|
189
|
+
n_boot: n_boot,
|
190
|
+
random: random,
|
191
|
+
sort: sort,
|
192
|
+
err_style: err_style,
|
193
|
+
err_params: err_params,
|
194
|
+
error_bar: error_bar,
|
195
|
+
x_scale: x_scale,
|
196
|
+
y_scale: y_scale,
|
197
|
+
legend: legend,
|
198
|
+
**options,
|
199
|
+
&block
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Scatter plot
|
204
|
+
#
|
205
|
+
# @param x [vector-like object, key in data]
|
206
|
+
# @param y [vector-like object, key in data]
|
207
|
+
# @param color [vector-like object, key in data]
|
208
|
+
# @param style [vector-like object, key in data]
|
209
|
+
# @param size [vector-like object, key in data]
|
210
|
+
# @param data [table-like object]
|
211
|
+
# @param key_color [color object]
|
212
|
+
# @param palette [String,Array<Numeric>,Palette]
|
213
|
+
# @param color_order [Array<String>,Array<Symbol>]
|
214
|
+
# @param color_norm
|
215
|
+
# @param sizes [Array, Hash]
|
216
|
+
# @param size_order [Array]
|
217
|
+
# @param size_norm
|
218
|
+
# @param markers [true, false, Array, Hash]
|
219
|
+
# @param style_order [Array]
|
220
|
+
# @param alpha [scalar number]
|
221
|
+
# Propotional opacity of the points.
|
222
|
+
# @param legend [:auto, :brief, :full, false]
|
223
|
+
# How to draw legend. If :brief, numeric color and size variables
|
224
|
+
# will be represented with a sample of evenly spaced values. If
|
225
|
+
# :full, every group will get an entry in the legend. If :auto,
|
226
|
+
# choose between brief or full representation based on number of
|
227
|
+
# levels. If false, no legend data is added and no legend is drawn.
|
228
|
+
def scatter_plot(x: nil, y: nil, color: nil, style: nil, size: nil,
|
229
|
+
data: nil, key_color: nil, palette: nil, color_order: nil,
|
230
|
+
color_norm: nil, sizes: nil, size_order: nil, size_norm: nil,
|
231
|
+
markers: true, style_order: nil, alpha: nil, legend: :auto,
|
232
|
+
**options, &block)
|
233
|
+
Plotters::ScatterPlotter.new(
|
234
|
+
data: data,
|
235
|
+
variables: { x: x, y: y, color: color, style: style, size: size },
|
236
|
+
key_color: key_color,
|
237
|
+
palette: palette,
|
238
|
+
color_order: color_order,
|
239
|
+
color_norm: color_norm,
|
240
|
+
sizes: sizes,
|
241
|
+
size_order: size_order,
|
242
|
+
size_norm: size_norm,
|
243
|
+
markers: markers,
|
244
|
+
style_order: style_order,
|
245
|
+
alpha: alpha,
|
246
|
+
legend: legend,
|
247
|
+
**options,
|
248
|
+
&block
|
249
|
+
)
|
250
|
+
end
|
251
|
+
|
252
|
+
def hist_plot(data: nil, x: nil, y: nil, color: nil,
|
253
|
+
stat: :count, bins: :auto,
|
254
|
+
key_color: nil, palette: nil, color_order: nil, color_norm: nil,
|
255
|
+
legend: true, **options, &block)
|
256
|
+
# TODO: support following arguments
|
257
|
+
# - wiehgts
|
258
|
+
# - binwidth
|
259
|
+
# - binrange
|
260
|
+
# - discrete
|
261
|
+
# - cumulative
|
262
|
+
# - common_bins
|
263
|
+
# - common_norm
|
264
|
+
# - multiple
|
265
|
+
# - element
|
266
|
+
# - fill
|
267
|
+
# - shrink
|
268
|
+
# - kde
|
269
|
+
# - kde_params
|
270
|
+
# - line_params
|
271
|
+
# - thresh
|
272
|
+
# - pthresh
|
273
|
+
# - pmax
|
274
|
+
# - cbar
|
275
|
+
# - cbar_params
|
276
|
+
# - x_log_scale
|
277
|
+
# - y_log_scale
|
278
|
+
Plotters::HistogramPlotter.new(
|
279
|
+
data: data,
|
280
|
+
variables: { x: x, y: y, color: color },
|
281
|
+
stat: stat,
|
282
|
+
bins: bins,
|
283
|
+
key_color: key_color,
|
284
|
+
palette: palette,
|
285
|
+
color_order: color_order,
|
286
|
+
color_norm: color_norm,
|
287
|
+
legend: legend,
|
288
|
+
**options,
|
289
|
+
&block)
|
15
290
|
end
|
16
291
|
end
|
17
292
|
|