Keyword arguments in PlotRecipes

plotting

#1

Following minimal example:

struct PlotType end
@recipe function f(::PlotType; title="Title", ylabel="ylabel")
    x := [1,2,3]
    y := rand(3,5)
end

The title is plotted fine, I also can change the title when calling the plot function plot(PlotType(),title="New Title"). However, the ylabel is not plotted, only when inserted as a keyword argument, i.e. plot(PlotType(),ylabel="New ylabel").

Any idea why or is there another solution to the problem, where I want to have default values for certain attributes, that might be overwritten by the user though when calling the plot function?


#2

I have realised a second problem with the code. Changing x does not change anything in the plot. It is still plotted from 1 to 3.

Any comments on that?


#3

I’m unsure what you want to do. What is the purpose of this recipe?
Labels are generally not inserted automatically in Plots.


#4

I just want to give the plot default values for the title and axis labels, which is working in the case of the title, but not in the case of the ylabel (using keywords).


#5

But what do you use the PlotType struct for? it doesn’t appear inside the recipe. Sometimes an example can be too minimal. I mean you could rewrite your mwe as

struct PlotType end
@recipe function f(::PlotType)
    title --> "Title"
    yguide --> "ylabel"
    x := [1,2,3]
    y := rand(3,5)
end

but I’m not sure that helps you do what you want ot do.