# Julia Plots.jl: changing marker colour from series recipe

**URL:** <https://discourse.julialang.org/t/julia-plots-jl-changing-marker-colour-from-series-recipe/12914>\
**Category:** Visualization\
**Tags:** plots, recipe\
**Created:** [August 5, 2018, 12:19pm UTC](https://discourse.julialang.org/t/julia-plots-jl-changing-marker-colour-from-series-recipe/12914 "2018-08-05T12:19:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanhevg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tanhevg/32/12025_2.png) [@tanhevg](https://discourse.julialang.org/u/tanhevg)\
**Post date:** [August 5, 2018, 12:19pm UTC](https://discourse.julialang.org/t/julia-plots-jl-changing-marker-colour-from-series-recipe/12914/1 "2018-08-05T12:19:17Z")

</div>

> <https://stackoverflow.com/questions/51677822/julia-plots-jl-changing-marker-colour-from-series-recipe>

I am trying to put together a `Plots.jl` user recipe, that would create several scatter plots and histograms arranged in a grid. The scatter plots should occupy the lower triangle of the grid. Histograms go on the diagonals. Each scatter plot should have several series, shown in different colours. The colours should be consistent across subplots.

My problem is when I allow the user to specify custom colours, the series colours in the scatter subplots get messed up.

Here is the (abridged) recipe code. `data` is is a vector of size `r`. Each element of `data` is a matrix of size `n_r x d`. `n_r` may vary, `d` stays the same. There should be `d x (d-1) / 2` scatter plots, with `r` series on each plot, each series having `n_r` points.

```
@recipe function my_func(data::my_type; custom_colors=nothing)
    # get d, r, ...
    for i in i:d
        for j in 1:d
            @series begin
                subplot := (i - 1) * d + j
                if i == j
                    seriestype := :histogram
                    plot_data = # ... prepare data for histograms
                elseif j < i
                    # scatter subplot recipe
                    seriestype := :scatter
                    if custom_colors !== nothing
                        color := reshape(custom_colors, (1, r))
                    end
                    x = Vector()
                    y = Vector()
                    for r in runs
                        ser = data[r]
                        append!(x, [ser[:, j]])
                        append!(y, [ser[:, i]])
                    end # for r
                    plot_data = (x, y)
                else
                    # leave empty
                    plot_data = [0]
                end # if/else
                plot_data # return from the macro function
            end # @series
        end # for j
    end # for i
end # @recipe

```

My problem is that whenever I supply custom colours, I get inconsistency across subplots:

```
plot(my_data, custom_colors=["blue", "green", "black"])

```

[plot with custom colors](https://i.stack.imgur.com/gPoNT.png)

Note how subplot (2, 1) has black dots in the middle, whereas all other scatter subplots have black on the outside

If I do the plot without custom colors:

```
plot(my_data)

```

I get consistent colours in all scatter subplots:

[plot with default colors](https://i.stack.imgur.com/XAF7P.png)

Any clues why the colours are mixed up on the first plot?

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [August 5, 2018, 12:51pm UTC](https://discourse.julialang.org/t/julia-plots-jl-changing-marker-colour-from-series-recipe/12914/2 "2018-08-05T12:51:12Z")

</div>

It’s typically not good form to just post a link to another site. Many of the active contributors here already monitor stack overflow, but if you want to use this forum to call attention to it it would be nice to include a bit of context rather than just a link.

---

<div class="post-metadata">

**Author:** ![tanhevg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tanhevg/32/12025_2.png) [@tanhevg](https://discourse.julialang.org/u/tanhevg)\
**Post date:** [August 5, 2018, 3:08pm UTC](https://discourse.julialang.org/t/julia-plots-jl-changing-marker-colour-from-series-recipe/12914/3 "2018-08-05T15:08:23Z")

</div>

Sorry, I thought the forum engine is intelligent enough to pull in the contents from SO, in the same manner as it has pulled in the header. Re-pasted the full question here as well. I wonder, what is the intention behind restricting the new posts to not more than one image?

---

<div class="post-metadata">

**Author:** ![tanhevg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tanhevg/32/12025_2.png) [@tanhevg](https://discourse.julialang.org/u/tanhevg)\
**Post date:** [August 5, 2018, 7:06pm UTC](https://discourse.julialang.org/t/julia-plots-jl-changing-marker-colour-from-series-recipe/12914/4 "2018-08-05T19:06:05Z")

</div>

Never mind, found the answer myself, and posted on SO
