From f32247a819bc938a133bb3403770814194821408 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 23 May 2024 18:11:31 +0200 Subject: [PATCH] add recipe for series on Plots v2 (#4941) * add recipe * add import * handle errorbars, add tests * improve test * simplify test * fix test --- PlotsBase/src/DataSeries.jl | 10 ++++++++++ PlotsBase/test/test_recipes.jl | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/PlotsBase/src/DataSeries.jl b/PlotsBase/src/DataSeries.jl index bb360eacd..507c05c6e 100644 --- a/PlotsBase/src/DataSeries.jl +++ b/PlotsBase/src/DataSeries.jl @@ -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) diff --git a/PlotsBase/test/test_recipes.jl b/PlotsBase/test/test_recipes.jl index 0c843fbaa..5666e668b 100644 --- a/PlotsBase/test/test_recipes.jl +++ b/PlotsBase/test/test_recipes.jl @@ -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)