File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -1620,4 +1620,30 @@ end
16201620 end
16211621end
16221622
1623+ # -------------------------------------------------
1624+ # Stem plots are useful for visualizing discretely sampled time series data
1625+ @userplot Stem
1626+
1627+ # If the second arg is a function, eagerly apply it so we can create the stem lines
1628+ process_stem_args(x, f:: Function ) = (x, f.(x))
1629+ process_stem_args(x, y) = (x, y)
1630+
1631+ @recipe function f(s:: Stem )
1632+ if length(s. args) != 2
1633+ throw(MethodError(stem, s. args))
1634+ end
1635+ x, y = process_stem_args(s. args... )
1636+ @series begin
1637+ primary := true
1638+ seriestype := :scatter
1639+ markerstrokewidth --> 0
1640+ x, y
1641+ end
1642+ @series begin
1643+ primary := false
1644+ seriestype := :line
1645+ [x x]' , [zero(y) y]'
1646+ end
1647+ end
1648+
16231649@specialize
Original file line number Diff line number Diff line change @@ -143,6 +143,20 @@ with(:gr) do
143143 @test_nowarn show(devnull , scatter3d(1 : 2 , 1 : 2 , 1 : 2 ))
144144 end
145145
146+ @testset " stem" begin
147+ n = 0 : 0.5 : 10
148+
149+ # Make sure array and function arguments work
150+ @test stem(n, sin.(n)) isa PlotsBase. Plot
151+ @test stem(n, sin) isa PlotsBase. Plot
152+
153+ # Should only accept two positional arguments, otherwise throw an error
154+ @test_throws MethodError stem()
155+ @test_throws MethodError stem(n)
156+ @test_throws MethodError stem(n, n, n)
157+ @test_throws MethodError stem(n, n, n, n)
158+ end
159+
146160 @testset " sticks" begin
147161 @test_nowarn show(devnull , sticks(1 : 2 , marker = :circle))
148162 end
You can’t perform that action at this time.
0 commit comments