From e8a24967a8699721dbbf1c741647256a2b8d300b Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 4 Jan 2024 17:31:06 +0900 Subject: [PATCH 1/3] 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 33ac49dae35aa4b7a0f689dbed83bf991c5711a7 Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 4 Jan 2024 18:36:05 +0900 Subject: [PATCH 2/3] add warning on possible mispell of args --- src/args.jl | 6 ++++++ src/backends/gr.jl | 2 ++ src/backends/pgfplotsx.jl | 1 + src/backends/pythonplot.jl | 3 +++ 4 files changed, 12 insertions(+) diff --git a/src/args.jl b/src/args.jl index 94c44f10b..9fdda0694 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1558,6 +1558,12 @@ function warn_on_unsupported_args(pkg::AbstractBackend, plotattributes) end end end + supported_extra_kws = extra_supported_kws(pkg) + for kw in keys(extra_kwargs) + if kw ∉ supported_extra_kws + @warn "Extra keyword argument $kw not explicitly supported with $pkg. Choose from: $(join(supported_extra_kws, ", "))" + end + end extra_kwargs end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 896e978fb..e41d8f442 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -104,6 +104,8 @@ const gr_font_family = Dict( "computer modern" => 232, "dejavu sans" => 233, ) +extra_supported_kws(::GRBackend) = + [:legend_hfactor, :legend_wfactor, :nx, :ny, :display_option] mutable struct GRViewport{T} xmin::T diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 28479b1c8..e03cc3eea 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -1,6 +1,7 @@ const Options = PGFPlotsX.Options const Table = PGFPlotsX.Table +extra_supported_kws(::PGFPlotsXBackend) = [:add] Base.@kwdef mutable struct PGFPlotsXPlot is_created::Bool = false was_shown::Bool = false diff --git a/src/backends/pythonplot.jl b/src/backends/pythonplot.jl index f1fc59df1..2fd09de0a 100644 --- a/src/backends/pythonplot.jl +++ b/src/backends/pythonplot.jl @@ -2,6 +2,9 @@ is_marker_supported(::PythonPlotBackend, shape::Shape) = true +extra_supported_kws(::PythonPlotBackend) = + [:levels, :mincnt, :edgecolors, :extend3d, :colors, :cmap, :facecolors, :shade] + # problem: github.com/tbreloff/Plots.jl/issues/308 # solution: hack from @stevengj: github.com/JuliaPy/PyPlot.jl/pull/223#issuecomment-229747768 let otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays)) From 428b460868e744329bcc282b9b65f504e0950188 Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 4 Jan 2024 18:46:34 +0900 Subject: [PATCH 3/3] handle base case --- src/backends.jl | 1 + src/backends/pythonplot.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/src/backends.jl b/src/backends.jl index 6b803858b..04905f81f 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -323,6 +323,7 @@ const _base_supported_args = [ :permute, :unitformat, ] +extra_supported_kws(pkg::AbstractBackend) = [] function merge_with_base_supported(v::AVec) v = vcat(v, _base_supported_args) diff --git a/src/backends/pythonplot.jl b/src/backends/pythonplot.jl index 2fd09de0a..3cbc43f1d 100644 --- a/src/backends/pythonplot.jl +++ b/src/backends/pythonplot.jl @@ -2,6 +2,7 @@ is_marker_supported(::PythonPlotBackend, shape::Shape) = true +# As this gets longer perhaps it should be a Set extra_supported_kws(::PythonPlotBackend) = [:levels, :mincnt, :edgecolors, :extend3d, :colors, :cmap, :facecolors, :shade]