From e8a24967a8699721dbbf1c741647256a2b8d300b Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 4 Jan 2024 17:31:06 +0900 Subject: [PATCH] offset arrays fix for hist --- src/recipes.jl | 10 ++++++---- test/test_recipes.jl | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index c4ad757c7..c82a0ff01 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -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]) diff --git a/test/test_recipes.jl b/test/test_recipes.jl index 9aa989e66..34273b172 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -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)