Skip to content

Commit

Permalink
offset arrays fix for hist
Browse files Browse the repository at this point in the history
  • Loading branch information
isentropic committed Jan 4, 2024
1 parent 806641a commit e8a2496
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@ function make_steps(x::AbstractArray, st, even)
n = length(x)
n == 0 && return zeros(0)
newx = zeros(2n - (even ? 0 : 1))
newx[1] = x[1]
xstartindex = firstindex(x)
newx[1] = x[xstartindex]
for i in 2:n
xindex = xstartindex - 1 + i
idx = 2i - 1
if st === :mid
newx[idx] = newx[idx - 1] = (x[i] + x[i - 1]) / 2
newx[idx] = newx[idx - 1] = (x[xindex] + x[xindex - 1]) / 2
else
newx[idx] = x[i]
newx[idx - 1] = x[st === :pre ? i : i - 1]
newx[idx] = x[xindex]
newx[idx - 1] = x[st === :pre ? xindex : xindex - 1]
end
end
even && (newx[end] = x[end])
Expand Down
7 changes: 7 additions & 0 deletions test/test_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ end
@test Plots.ylims(vsp) == (-2, 5)
end

@testset "steps offset" begin
data = OffsetArray(rand(11), -5:5)
plot(data, linetype = :steppre)
plot(data, linetype = :stepmid)
plot(data, linetype = :steppost)
end

@testset "offset axes" begin
tri = OffsetVector(vcat(1:5, 4:-1:1), 11:19)
sticks = plot(tri, seriestype = :sticks)
Expand Down

0 comments on commit e8a2496

Please sign in to comment.