Skip to content

Commit

Permalink
add recipe for series on Plots v2 (#4941)
Browse files Browse the repository at this point in the history
* add recipe

* add import

* handle errorbars, add tests

* improve test

* simplify test

* fix test
  • Loading branch information
BeastyBlacksmith authored May 23, 2024
1 parent 3db0408 commit f32247a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions PlotsBase/src/DataSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ export get_linestyle,
get_markercolor,
get_markeralpha

import Base.show
import ..Commons: get_gradient, get_subplot, _series_defaults
import ..PlotsBase

using ..PlotsBase: DefaultsDict, RecipesPipeline, get_attr_symbol, KW
using ..PlotUtils: ColorGradient, plot_color
using ..RecipesBase: @recipe
using ..Commons

mutable struct Series
plotattributes::DefaultsDict
end

@recipe function f(s::Series)
for (k, v) in s.plotattributes
k in (:subplot, :yerror, :xerror, :zerror) && continue
plotattributes[k] = v
end
()
end

Base.getindex(series::Series, k::Symbol) = series.plotattributes[k]
Base.setindex!(series::Series, v, k::Symbol) = (series.plotattributes[k] = v)
Base.get(series::Series, k::Symbol, v) = get(series.plotattributes, k, v)
Expand Down
6 changes: 6 additions & 0 deletions PlotsBase/test/test_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ using OffsetArrays
end
end

@testset "Series" begin
pl = plot(1:3, yerror = 1)
@test plot(pl[1][1])[1][1][:primary] == true
@test plot(pl[1][2])[1][1][:primary] == false
@test isequal(plot(pl[1][2])[1][1][:y], pl[1][2][:y])
end
@testset "lens!" begin
pl = plot(1:5)
lens!(pl, [1, 2], [1, 2], inset = (1, bbox(0.0, 0.0, 0.2, 0.2)), colorbar = false)
Expand Down

0 comments on commit f32247a

Please sign in to comment.