Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,11 @@
"affiliation": "@JuliaComputing",
"name": "Παναγιώτης Γεωργακόπουλος",
"type": "Other"
},
{
"affiliation": "@ZiplineTeam",
"name": "Jonnie Diegelman",
"type": "Other"
}
],
"upload_type": "software"
Expand Down
26 changes: 26 additions & 0 deletions PlotsBase/src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions PlotsBase/test/test_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading