# What does the \`primary\` attribute do and how to plot curves with scatters added onto it in \`Plots.jl\`?

**URL:** https://discourse.julialang.org/t/what-does-the-primary-attribute-do-and-how-to-plot-curves-with-scatters-added-onto-it-in-plots-jl/93486
**Category:** General Usage
**Tags:** plotting, recipe
**Created:** [January 25, 2023, 3:13am UTC](https://discourse.julialang.org/t/what-does-the-primary-attribute-do-and-how-to-plot-curves-with-scatters-added-onto-it-in-plots-jl/93486 "2023-01-25T03:13:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)
#### Post date: [January 25, 2023, 3:13am UTC](https://discourse.julialang.org/t/what-does-the-primary-attribute-do-and-how-to-plot-curves-with-scatters-added-onto-it-in-plots-jl/93486/1 "2023-01-25T03:13:15Z")

</div>

For example, we have the following recipe:

```julia
using RecipesBase: @userplot, @recipe, @series

@userplot MyPlot
@recipe function f(plot::MyPlot)
    x, y = plot.args
    palette --> :tab20
    @series begin
        seriestype --> :scatter
        primary := false
        x, y
    end
    seriestype --> :path
    label --> ""
    return x, y
end

```

and the following data:

```julia
x = 1:10
y = x.^2 .+ 1 .+ rand(10)

x1 = 2:2:20
y1 = x1.^1.5 .+ rand(10)

x2 = 3:3:30
y2 = x2 / 10 .+ 10

```

So we plot:

```julia
julia> myplot(x, y; label="xy")

julia> myplot!(x1, y1; label="x1y1")

julia> myplot!(x2, y2; label="x2y2")

```

and get the following figure:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/6/f6a449d9d8530c131a29ffe1a796002f716a3613.png)

As you can see, the color of the scatters and the lines are not matched in each set of data.  
What we want is something like this:

```julia
@userplot MyPlot2
@recipe function f(plot::MyPlot2)
    x, y = plot.args
    palette --> :tab20
    @series begin
        seriestype --> :scatter
        label := ""
        x, y
    end
    seriestype --> :path
    label --> ""
    return x, y
end

julia> myplot2(x, y; label="xy")

julia> myplot2!(x1, y1; label="x1y1")

julia> myplot2!(x2, y2; label="x2y2")

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/e/0ed3dec56d07e0c9c2d9f7067af154396bf93ffe.png)

Am I using `:tab20` correctly? Is it supposed to be used this way? Why does not `primary = false` not work here?

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [January 25, 2023, 9:17am UTC](https://discourse.julialang.org/t/what-does-the-primary-attribute-do-and-how-to-plot-curves-with-scatters-added-onto-it-in-plots-jl/93486/2 "2023-01-25T09:17:03Z")

</div>

Well, setting `primary = false` will cause a series to have the same color as the preceeding series.  
Therefore it won’t give you what you are after, if you set that for the first series of the plot.  
The following will work better:

```julia
@userplot MyPlot
@recipe function f(plot::MyPlot)
    x, y = plot.args
    palette --> :tab20
    @series begin
        seriestype --> :scatter
        x, y
    end
    primary := false
    seriestype --> :path
    label --> ""
    return x, y
end

```

However, if all you want is to have markers on your path, its enough to set `markershape`.
