Problem with changing color map inside plot recipe

Consider the following plot recipe:

using RecipesBase

struct DummyType end

@recipe function f(dummy::DummyType)
    @series begin
        seriestype := :contourf
        color --> :bluesreds
        
        [i+j for i in 1:10, j in 1:10]
    end
end

It works fine as illustrated below:

using Plots; gr()

plot(DummyType())

dummy

However, if I try to set the default color map to something else like in

plot(DummyType(), color=:plasma)

the option doesn’t take effect, and I get back the same color map as before.

Could you please explain what is happening?

That’s because color isn’t the actual name of the attribute - the attribute is seriescolor and color is just a short alias for it. You should always use the full name of the attribute in a recipe (you can find that with plotattr("color")).

@recipe function f(dummy::DummyType)
    @series begin
        seriestype := :contourf
        seriescolor --> :bluesreds
        
        [i+j for i in 1:10, j in 1:10]
    end
end
plot(DummyType(), color=:plasma)

16

2 Likes

Thank you @mkborregaard, on the spot. :+1: :slight_smile: Also thanks for reminding me of plotattr(), I need to use it more in the future.

1 Like