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

reset fillto for logscale barplots #4782

Merged
merged 1 commit into from
Jul 25, 2023
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
10 changes: 8 additions & 2 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ end

# create a bar plot as a filled step function
@recipe function f(::Type{Val{:bar}}, x, y, z) # COV_EXCL_LINE
ywiden --> false
procx, procy, xscale, yscale, _ = _preprocess_barlike(plotattributes, x, y)
nx, ny = length(procx), length(procy)
axis = plotattributes[:subplot][isvertical(plotattributes) ? :xaxis : :yaxis]
Expand Down Expand Up @@ -435,9 +436,14 @@ end
end
if yscale in _logScales && !all(_is_positive, fillto)
# github.com/JuliaPlots/Plots.jl/issues/4502
# https://github.com/JuliaPlots/Plots.jl/issues/4774
T = float(eltype(y))
min_y, _ = plotattributes[:y_extrema]
baseline = floor_base(min_y, _logScaleBases[yscale])
min_y = NaNMath.minimum(y)
base = _logScaleBases[yscale]
baseline = floor_base(min_y, base)
if min_y == baseline
baseline /= base
end
fillto = map(x -> _is_positive(x) ? T(x) : T(baseline), fillto)
end

Expand Down
19 changes: 10 additions & 9 deletions test/test_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,36 @@ with(:gr) do
end

@testset "parametric" begin
@test plot(sin, sin, cos, 0, 2π) isa Plot
@test plot(sin, sin, cos, collect((-2π):(π / 4):(2π))) isa Plot
@test plot(sin, sin, cos, 0, 2π) isa Plots.Plot
@test plot(sin, sin, cos, collect((-2π):(π / 4):(2π))) isa Plots.Plot
end

@testset "dict" begin
show(devnull, plot(Dict(1 => 2, 3 => -1)))
@test_nowarn show(devnull, plot(Dict(1 => 2, 3 => -1)))
end

@testset "gray image" begin
show(devnull, plot(rand(Gray, 2, 2)))
@test_nowarn show(devnull, plot(rand(Gray, 2, 2)))
end

@testset "plots_heatmap" begin
show(devnull, plots_heatmap(rand(RGBA, 2, 2)))
@test_nowarn show(devnull, plots_heatmap(rand(RGBA, 2, 2)))
end

@testset "scatter3d" begin
show(devnull, scatter3d(1:2, 1:2, 1:2))
@test_nowarn show(devnull, scatter3d(1:2, 1:2, 1:2))
end

@testset "sticks" begin
show(devnull, sticks(1:2, marker = :circle))
@test_nowarn show(devnull, sticks(1:2, marker = :circle))
end

@testset "stephist" begin
show(devnull, stephist([1, 2], marker = :circle))
@test_nowarn show(devnull, stephist([1, 2], marker = :circle))
end

@testset "bar with logscales" begin
show(devnull, bar([1 2 3], [0.02 125 10_000]; yscale = :log10))
@test_nowarn show(devnull, bar([1 2 3], [0.02 125 10_000]; yscale = :log10))
@test_nowarn histogram(randn(100), yscale = :log10)
end
end
Loading