# Consistent plotting attributes

**URL:** https://discourse.julialang.org/t/consistent-plotting-attributes/10822
**Category:** Visualization
**Tags:** question
**Created:** [May 10, 2018, 5:35pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822 "2018-05-10T17:35:30Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 10, 2018, 5:35pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/1 "2018-05-10T17:35:30Z")

</div>

I’m plotting the same stuff across multiple different plots. To make things look consistent I want the same things to have the same look, regardless of which plot they are in. What is the best way to accomplish that?

Here’s a MWE. Two different plots, in both are a `path`, `home`, and `work`. These are colored and shaped consistently. I’m basically trying to avoid from repeatedly setting the attributes of the plotted content. I tried using a `Dict` but couldn’t get to work…

```julia
plot(rand(5), color = :green, label = "path")
scatter!(rand(1), rand(1), markershape = :star5, markercolor = :red, label = "home")
scatter!(rand(1), rand(1), markershape = :pentagon, markercolor = :blue, label = "work")

plot(rand(5), proj=:polar, color = :green, label = "path")
scatter!(rand(1), rand(1), markershape = :star5, markercolor = :red, label = "home")
scatter!(rand(1), rand(1), markershape = :pentagon, markercolor = :blue, label = "work")

```

Any help appreciated!

---

<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: [May 10, 2018, 6:23pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/2 "2018-05-10T18:23:22Z")

</div>

The Plots ideomatic way is to create a series recipe:

```julia
@recipe function f(::Type{Val{:home}}, x,y,z)
       seriescolor := :red
       markershape := :star5
       seriestype := :scatter
       x,y
  end

plot(rand(5), st = :home)

```

Unfortunately it looks as if Plots is currently ignoring :seriescolor in recipes. Not sure what’s going on there.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 10, 2018, 6:38pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/3 "2018-05-10T18:38:14Z")

</div>

Oooo, that looks like exactly what I wanted. Except for the color glitch…

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 10, 2018, 6:41pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/4 "2018-05-10T18:41:17Z")

</div>

Posted an [issue](https://github.com/JuliaPlots/Plots.jl/issues/1520).

---

<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: [May 10, 2018, 7:07pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/5 "2018-05-10T19:07:31Z")

</div>

Thanks! Oh, and remember you shouldn’t define a new series recipe named `:path` 🙂

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 10, 2018, 7:08pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/6 "2018-05-10T19:08:20Z")

</div>

👍 thank you for that (I would have…)

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [May 20, 2018, 12:12pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/7 "2018-05-20T12:12:42Z")

</div>

Not a solution, but instead hijacking this thread to get feedback on how I’m solving this in Makie:

```nohighlight

path = Theme(color = :green, label = "path")
home = Theme(markershape = :star5, markercolor = :red, label = "home")
work = Theme(markershape = :pentagon, markercolor = :blue, label = "work")

plot(path, rand(5))
scatter!(home, rand(1), rand(1))
scatter!(work, rand(1), rand(1))

plot(path, rand(5), proj = :polar)
scatter!(home, rand(1), rand(1))
scatter!(work, rand(1), rand(1))

```

I also plan to offer the following, but I still need to figure out how to not make it ambigious:

```nohighlight
path = plot(rand(5), color = :green, label = "path")
home = scatter!(rand(1), rand(1), markershape = :star5, markercolor = :red, label = "home")
work = scatter!(rand(1), rand(1), markershape = :pentagon, markercolor = :blue, label = "work")

plot(path, rand(5), proj=:polar)
# the below is ambigious with just updating the `home` plot in place, so it might need to be wrapped in
# `attributes(home)`
scatter!(home, rand(1), rand(1))
scatter!(work, rand(1), rand(1))

```

Alternatively, this would be the equivalent recipe solution in Makie:

```nohighlight

@recipe(path) do scene
    Theme(color = :green, label = "path")
end
@recipe(home) do scene
    Theme(markershape = :star5, markercolor = :red, label = "home")
end
@recipe(work) do scene
    Theme(markershape = :pentagon, markercolor = :blue, label = "work")
end

path = path(rand(5))
home = home!(rand(1), rand(1))
work = work!(rand(1), rand(1))

```

Do those look like viable solutions as well?

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [May 20, 2018, 2:07pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/8 "2018-05-20T14:07:50Z")

</div>

@sdanisch I am looking forward to try `Makie.jl` and migrate the plot recipes defined in my packages to the `Makie.jl`-equivalents. What are your plans for the first release of the project?

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [May 20, 2018, 2:22pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/9 "2018-05-20T14:22:02Z")

</div>

I think it’s very important to have a `Theme` object that can collect all defaults for a user (say in a paper one wants to be consistent across all figures), so I think this is a great idea.

The second extra (and ambiguous) method for `scatter!` is probably not required, couldn’t you instead say that `Theme` applied to a plot object takes all its attributes? So you would have:

```julia
path = plot(rand(5), color = :green, label = "path")
home = scatter!(rand(1), rand(1), markershape = :star5, markercolor = :red, label = "home")
work = scatter!(rand(1), rand(1), markershape = :pentagon, markercolor = :blue, label = "work")

plot(Theme(path), rand(5), proj=:polar)
scatter!(Theme(home), rand(1), rand(1))
scatter!(Theme(work), rand(1), rand(1))

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 20, 2018, 5:01pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/10 "2018-05-20T17:01:14Z")

</div>

Yes!

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [May 21, 2018, 12:49am UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/11 "2018-05-21T00:49:25Z")

</div>

@sdanisch how will you call the edge line attribute of a marker? In GMT I’m following the Matlab naming of _markerfacecolor_ and _markeredgecolor_

---

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [May 21, 2018, 1:00pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/12 "2018-05-21T13:00:47Z")

</div>

One question on a design choice made in Plots – and possibly in Makie?

The basic data structure appears to be a _matrix_ where each column is treated as a series to be plotted. Because of this, if I want to assign different colors to each series, I need to specify a row matrix of colors. Thus, suppose `M` is a matrix of `3` columns. Then I plot them with different colors by writing.

```julia
plot(M, lc=[:red :blue :green])

```

Alternatively, I can plot a _vector_ of vectors, say vectors `v1`, `v2`, `v3` by:

```julia
plot([v1,v2,v3], lc=[:red :blue :green])

```

Here, the data are given as a vector of vectors, but I _still_ have to specify the colors as a row matrix. This takes some artificial logic to explain – essentially, that the vector of vectors is a “matrix”.

An **alternative** approach would be to say that it is a vector of vectors that is the primary data structure for plotting, and thus require line colors, linewidth, linestyle, etc. to be given as a _vector_ of elements, e.g.,

```julia
plot([v1,v2,v3], lc=[:red, :blue, :green])

```

Of course, the artificial logic would still be there for explaining why data could alternatively be given as columns in a matrix. However:

1. To some degree, the vector of vectors _is_ a slightly more general way to give the data, e.g., if one wants to give the data as _functions_ – `plot([sin,cos])`,
2. A list of colors is more easily given as a vector of colors, e.g., as `linspace(:red,:blue,5)` which produces a vector of colors. In current plots, this must be _reshaped_ into a row matrix before assigned to the linecolor.
3. It is also (perhaps?) easier to give labels in a for loop as a _vector of strings_, say if each data series represent a unique parameter value and one wants the label to include information about the parameter value. With today’s syntax, this must be reshaped into a row matrix.

OK – I’m not a super expert on `Plots`, so there may be other reasons why keyword values are given as row matrices. But with my current understanding, it seems like it would both be somewhat simpler to explain the logics, and simpler to use `Plots` if a vector of vectors (or a vector of matrices in case of surface plots) were the standard.

Anyway, I’m curious to learn if there are some more hidden depths behind choosing matrix as the fundamental data structure.

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [May 21, 2018, 1:59pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/13 "2018-05-21T13:59:21Z")

</div>

@piever

That’s basically what I proposed with

> might need wrapping in `attributes(home)`

Using `Theme` instead of `attributes` would also be a good (better?) option!

@juliohm I really hope to have first prototype ready this week. The upper bound for a release is before JuliaCon! I’m also working with a JSOC student on a full documentation for Makie, which should be finished at the end of the coding period (August 14th or so!). So that’s the date you can expect a fairly stable package.

@BLI

I sympathise with most of what you’re saying.  
The beauty of Makie is, that the current behaviour of Plots.jl is ported as a recipe _itself_.  
So we’re free to change how to do things as there is nothing in the internals of Makie that will hold as back.  
We can also create some default behaviour, and have a completely different behaviour in a surface syntax package - e.g. GGPlot.jl/MakieMatplotlib.jl or whatever 😉

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 25, 2018, 12:47pm UTC](https://discourse.julialang.org/t/consistent-plotting-attributes/10822/14 "2018-05-25T12:47:52Z")

</div>

> [@mkborregaard](#):
>
> Unfortunately it looks as if Plots is currently ignoring :seriescolor in recipes

Just wanted to let you all know that after the last update to `Plots`, it now works. So :seriescolor is **not** ignored any longer 🙂
