# Keyword arguments in PlotRecipes

**URL:** <https://discourse.julialang.org/t/keyword-arguments-in-plotrecipes/20780>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [February 14, 2019, 8:26am UTC](https://discourse.julialang.org/t/keyword-arguments-in-plotrecipes/20780 "2019-02-14T08:26:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 14, 2019, 8:26am UTC](https://discourse.julialang.org/t/keyword-arguments-in-plotrecipes/20780/1 "2019-02-14T08:26:42Z")

</div>

Following minimal example:

```julia
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?

---

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 14, 2019, 10:43am UTC](https://discourse.julialang.org/t/keyword-arguments-in-plotrecipes/20780/2 "2019-02-14T10:43:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 18, 2019, 9:28am UTC](https://discourse.julialang.org/t/keyword-arguments-in-plotrecipes/20780/3 "2019-02-18T09:28:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 20, 2019, 7:04am UTC](https://discourse.julialang.org/t/keyword-arguments-in-plotrecipes/20780/4 "2019-02-20T07:04:04Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 20, 2019, 7:45am UTC](https://discourse.julialang.org/t/keyword-arguments-in-plotrecipes/20780/5 "2019-02-20T07:45:52Z")

</div>

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

```julia
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.
