From e8a24967a8699721dbbf1c741647256a2b8d300b Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 4 Jan 2024 17:31:06 +0900 Subject: [PATCH 1/2] 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) From 0215f718ac32b00fd8b5b161ae7359dac129747b Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 4 Jan 2024 19:38:47 +0900 Subject: [PATCH 2/2] fix python twin ax --- src/backends/pythonplot.jl | 4 ++-- test/test_axes.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backends/pythonplot.jl b/src/backends/pythonplot.jl index f1fc59df1..421c11fc9 100644 --- a/src/backends/pythonplot.jl +++ b/src/backends/pythonplot.jl @@ -1229,10 +1229,10 @@ function _before_layout_calcs(plt::Plot{PythonPlotBackend}) # link axes x_ax_link, y_ax_link = xaxis.sps[1].o, yaxis.sps[1].o if Bool(ax != x_ax_link) # twinx - ax.get_shared_x_axes().join(ax, x_ax_link) + ax.sharey(y_ax_link) end if Bool(ax != y_ax_link) # twiny - ax.get_shared_y_axes().join(ax, y_ax_link) + ax.sharex(x_ax_link) end end # for sp in pl.subplots _py_drawfig(fig) diff --git a/test/test_axes.jl b/test/test_axes.jl index d06eabc5e..62092ac5b 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -141,7 +141,7 @@ end @testset "Twinx" begin pl = plot(1:10, margin = 2Plots.cm) twpl = twinx(pl) - pl! = plot!(twinx(), -(1:10)) + pl! = plot!(twpl, -(1:10)) @test twpl[:right_margin] == 2Plots.cm @test twpl[:left_margin] == 2Plots.cm @test twpl[:top_margin] == 2Plots.cm