Skip to content

Commit

Permalink
set fill beneath min_y by default
Browse files Browse the repository at this point in the history
  • Loading branch information
BeastyBlacksmith committed Jun 23, 2023
1 parent 1b822b9 commit ec9461a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
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

0 comments on commit ec9461a

Please sign in to comment.