Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bar_plot log with log parameter #110

Merged
merged 3 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "matplotlib", ">= 1.2.0"
spec.add_dependency "pandas", ">= 0.3.5"
spec.add_dependency "playwright-ruby-client"
spec.add_dependency "pycall", ">= 1.5.2"

spec.add_development_dependency "bundler", ">= 1.16"
spec.add_development_dependency "rake"
Expand Down
14 changes: 9 additions & 5 deletions lib/charty/plotters/bar_plotter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,21 @@ def log=(val)
super

if self.log
min_value, max_value = @estimations.minmax
if @plot_colors
min_value = @estimations.map(&:min).min
max_value = @estimations.map(&:max).max
unless @conf_int.empty?
min_value = [min_value, @conf_int[0]].min
max_value = [max_value, @conf_int[1]].max
ci_min = @conf_int.map {|cis| cis.map {|ci| ci[0] }.min }.min
ci_max = @conf_int.map {|cis| cis.map {|ci| ci[1] }.max }.max
min_value = [min_value, ci_min].min
max_value = [max_value, ci_max].max
end
else
min_value, max_value = @estimations.minmax
ci_min = Util.filter_map(@conf_int) { |ci| ci[0] unless ci.empty? }
ci_max = Util.filter_map(@conf_int) { |ci| ci[1] unless ci.empty? }
min_value = [min_value, ci_min.min].min unless ci_min.empty?
max_value = [max_value, ci_max.max].max unless ci_max.empty?
min_value = [min_value, *ci_min].min
max_value = [max_value, *ci_max].max
end
if min_value > 1
min_value = 0
Expand Down
20 changes: 20 additions & 0 deletions test/plot_methods/bar_plot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ def test_bar_plot_sd(data)
render_plot(backend_name, plot)
end
end

def test_bar_plot_log(data)
adapter_name, backend_name = data.values_at(:adapter, :backend)
setup_data(adapter_name)
setup_backend(backend_name)
plot = Charty.bar_plot(data: @data, x: :x, y: :y, log: true)
assert_nothing_raised do
render_plot(backend_name, plot)
end
end

def test_bar_plot_log_with_color(data)
adapter_name, backend_name = data.values_at(:adapter, :backend)
setup_data(adapter_name)
setup_backend(backend_name)
plot = Charty.bar_plot(data: @data, x: :x, y: :y, color: :c, log: true)
assert_nothing_raised do
render_plot(backend_name, plot)
end
end
end

sub_test_case("with nonzero origin index") do # [GH-93]
Expand Down
Loading