diff --git a/.zenodo.json b/.zenodo.json index 687427c75..c848815cf 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -814,6 +814,11 @@ "affiliation": "@JuliaComputing", "name": "Παναγιώτης Γεωργακόπουλος", "type": "Other" + }, + { + "affiliation": "@ZiplineTeam", + "name": "Jonnie Diegelman", + "type": "Other" } ], "upload_type": "software" diff --git a/PlotsBase/src/recipes.jl b/PlotsBase/src/recipes.jl index b4cf773b3..b55d2bfd0 100644 --- a/PlotsBase/src/recipes.jl +++ b/PlotsBase/src/recipes.jl @@ -1620,4 +1620,30 @@ end end end +# ------------------------------------------------- +# Stem plots are useful for visualizing discretely sampled time series data +@userplot Stem + +# If the second arg is a function, eagerly apply it so we can create the stem lines +process_stem_args(x, f::Function) = (x, f.(x)) +process_stem_args(x, y) = (x, y) + +@recipe function f(s::Stem) + if length(s.args) != 2 + throw(MethodError(stem, s.args)) + end + x, y = process_stem_args(s.args...) + @series begin + primary := true + seriestype := :scatter + markerstrokewidth --> 0 + x, y + end + @series begin + primary := false + seriestype := :line + [x x]', [zero(y) y]' + end +end + @specialize diff --git a/PlotsBase/test/test_recipes.jl b/PlotsBase/test/test_recipes.jl index dade6ff4e..a7750736d 100644 --- a/PlotsBase/test/test_recipes.jl +++ b/PlotsBase/test/test_recipes.jl @@ -143,6 +143,20 @@ with(:gr) do @test_nowarn show(devnull, scatter3d(1:2, 1:2, 1:2)) end + @testset "stem" begin + n = 0:0.5:10 + + # Make sure array and function arguments work + @test stem(n, sin.(n)) isa PlotsBase.Plot + @test stem(n, sin) isa PlotsBase.Plot + + # Should only accept two positional arguments, otherwise throw an error + @test_throws MethodError stem() + @test_throws MethodError stem(n) + @test_throws MethodError stem(n, n, n) + @test_throws MethodError stem(n, n, n, n) + end + @testset "sticks" begin @test_nowarn show(devnull, sticks(1:2, marker = :circle)) end