From 83ade83099b6c1ebe84438d0b93582d9c93abeba Mon Sep 17 00:00:00 2001 From: rafaqz Date: Wed, 13 Sep 2023 22:34:45 +0200 Subject: [PATCH] resample for series --- ext/DimensionalDataMakie.jl | 16 ++++++++++++++-- test/plotrecipes.jl | 15 +++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ext/DimensionalDataMakie.jl b/ext/DimensionalDataMakie.jl index 2ca60e496..dcb87f786 100644 --- a/ext/DimensionalDataMakie.jl +++ b/ext/DimensionalDataMakie.jl @@ -238,9 +238,21 @@ Plot a 2-dimensional `AbstractDimArray` with `Makie.series`. $(_labeldim_detection_doc(series)) """ -function Makie.series(A::AbstractDimArray{<:Any,2}; axislegendkw=(;), labeldim=nothing, attributes...) +function Makie.series(A::AbstractDimArray{<:Any,2}; + colormap=:Set1_5, color=nothing, axislegendkw=(;), labeldim=nothing, attributes..., +) args, merged_attributes = _series(A, attributes, labeldim) - p = Makie.series(args...; merged_attributes...) + n = size(last(args), 1) + p = if isnothing(color) + if n > 7 + color = resample_cmap(colormap, n) + Makie.series(args...; color, colormap, merged_attributes...) + else + Makie.series(args...; colormap, merged_attributes...) + end + else + Makie.series(args...; color, colormap, merged_attributes...) + end axislegend(p.axis; merge=true, unique=false, axislegendkw...) return p end diff --git a/test/plotrecipes.jl b/test/plotrecipes.jl index 9f0d6c727..6ec14edae 100644 --- a/test/plotrecipes.jl +++ b/test/plotrecipes.jl @@ -182,14 +182,21 @@ if !haskey(ENV, "CI") # Series also puts Categories in the legend no matter where they are series(A2) series(A2r) - dd = DimArray(rand(10,20), (:a, :b)) - series(dd) + series(A2r; labeldim=Y) + @test_throws ArgumentError plot(A2; y=:c) # x/y can be specified - A2 = DimArray(rand(10, 10), (:a, :b); name=:stuff) + A2ab = DimArray(rand(6, 10), (:a, :b); name=:stuff) plot(A2ab) contourf(A2ab; x=:a) heatmap(A2ab; y=:b) - @test_throws ArgumentError plot(A2; y=:c) + series(A2ab) + boxplot(A2ab) + violin(A2ab) + rainclouds(A2ab) + surface(A2ab) + series(A2ab) + series(A2ab; labeldim=:a) + series(A2ab; labeldim=:b) # 3d A3 = rand(X(7), Z(10), Y(5)) volume(A3)