RecipesBase: Text in plot recipe?

Is there a way to add text to a plot recipe?

I’ve tried @annotate and a variety of things without success. The docs don’t mention it - that I can find anyways : Recipes · Plots

You can assign to the keyword arguments, such as hover etc. like you would any other keyword argument.

See for example here

1 Like

I’m still having no luck here’s a reproducible example

struct toy 
    x
    y
end

@recipe function toyplot(X::toy)
    seriestype := :scatter
    title := "toy"
    @series begin
        y := (X.x, X.y)
        annotation := (1, -1, "Look up!") 
    end
end

plot( toy( [2,3,4,5],[1,2,3,4] ) )

I keep getting this error depending on the command I try(Including hove). I’ve tried symbols, etc, no luck.

No user recipe defined for String

Try this

@recipe function toyplot(X::toy)
    seriestype := :scatter
    title := "toy"
    @series begin
        annotation := (1, -1, "Look up!")
        X.x, X.y
    end
end

I have no idea how you figured that out, but I appreciate it. I had to change it a little so the text displayed on the plot but it works

@recipe function toyplot(X::toy)
    seriestype := :scatter
    title := "toy"
    @series begin
        annotation := (3, 4, "Look up!")
        X.x, X.y
    end
end

Thank you!

1 Like

You typically return the stuff to be plotted, i.e., place x and y last in the @series

1 Like