Skip to content

Commit f32247a

Browse files
add recipe for series on Plots v2 (#4941)
* add recipe * add import * handle errorbars, add tests * improve test * simplify test * fix test
1 parent 3db0408 commit f32247a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

PlotsBase/src/DataSeries.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,27 @@ export get_linestyle,
2121
get_markercolor,
2222
get_markeralpha
2323

24+
import Base.show
2425
import ..Commons: get_gradient, get_subplot, _series_defaults
2526
import ..PlotsBase
2627

2728
using ..PlotsBase: DefaultsDict, RecipesPipeline, get_attr_symbol, KW
2829
using ..PlotUtils: ColorGradient, plot_color
30+
using ..RecipesBase: @recipe
2931
using ..Commons
3032

3133
mutable struct Series
3234
plotattributes::DefaultsDict
3335
end
3436

37+
@recipe function f(s::Series)
38+
for (k, v) in s.plotattributes
39+
k in (:subplot, :yerror, :xerror, :zerror) && continue
40+
plotattributes[k] = v
41+
end
42+
()
43+
end
44+
3545
Base.getindex(series::Series, k::Symbol) = series.plotattributes[k]
3646
Base.setindex!(series::Series, v, k::Symbol) = (series.plotattributes[k] = v)
3747
Base.get(series::Series, k::Symbol, v) = get(series.plotattributes, k, v)

PlotsBase/test/test_recipes.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ using OffsetArrays
2020
end
2121
end
2222

23+
@testset "Series" begin
24+
pl = plot(1:3, yerror = 1)
25+
@test plot(pl[1][1])[1][1][:primary] == true
26+
@test plot(pl[1][2])[1][1][:primary] == false
27+
@test isequal(plot(pl[1][2])[1][1][:y], pl[1][2][:y])
28+
end
2329
@testset "lens!" begin
2430
pl = plot(1:5)
2531
lens!(pl, [1, 2], [1, 2], inset = (1, bbox(0.0, 0.0, 0.2, 0.2)), colorbar = false)

0 commit comments

Comments
 (0)