# Plots multiple groups of series from a dataframe (seems a bug in plots?)

**URL:** <https://discourse.julialang.org/t/plots-multiple-groups-of-series-from-a-dataframe-seems-a-bug-in-plots/2246>\
**Category:** Visualization\
**Tags:** question, plotting, pyplot\
**Created:** [February 23, 2017, 9:15am UTC](https://discourse.julialang.org/t/plots-multiple-groups-of-series-from-a-dataframe-seems-a-bug-in-plots/2246 "2017-02-23T09:15:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 23, 2017, 9:15am UTC](https://discourse.julialang.org/t/plots-multiple-groups-of-series-from-a-dataframe-seems-a-bug-in-plots/2246/1 "2017-02-23T09:15:51Z")

</div>

I am trying to plot multiple groups of series from a dataframe, distinguish the group by line attribute and the individual serie by colour.  
The problem is that, although I define my own palette, only the first group of series complies with it:

```julia
using DataFrames, Plots, StatPlots
df = DataFrame(
  product = ["orange","orange","orange","orange","banana","banana","banana","banana"],
  year = [2010,2011,2012,2013,2010,2011,2012,2013],
  prod = [120,150,170,160,100,130,165,158],
  cons = [70,90,100,95, 80,95,110,120]
)
plotlyjs() # same with pyplot() backend..
mycolors = [:blue, :red] # same with mycolors = [:yellow, :orange]
fruits_plot = plot(df, :year, :prod, group=:product, linestyle = :solid, linewidth=3, linecolor=:match, color_palette = mycolors)
fruits_plot = plot!(df, :year, :cons, group=:product, linestyle = :dot, linewidth=3, linecolor=:match, color_palette = mycolors)

```

Produces:

 ![](https://global.discourse-cdn.com/julialang/original/3X/7/a/7a66cf68f1f850b56d89b901213b288686e5b354.png)

As you can see, the second group of series is using the palette, but with somehow “distorted” colours.  
It’s not because it’s a :dot (I did try with :solid for the second group of series too).  
Am I doing something wrong, or you think it’s a bug in the Plots package?

On a side note, would it be possible to force adding a prefix to the legend, so I could write "Production of " for the first group and "Consumption of " for the second one ?..

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 23, 2017, 10:42am UTC](https://discourse.julialang.org/t/plots-multiple-groups-of-series-from-a-dataframe-seems-a-bug-in-plots/2246/2 "2017-02-23T10:42:37Z")

</div>

I did open a [bug report](https://github.com/JuliaPlots/Plots.jl/issues/701) on the Plots.jl package for the colour issue and a [feature request](https://github.com/JuliaPlots/Plots.jl/issues/700) for the label one… Still, feel free to comment if you believe there are workarounds to that (of if I am taking the wrong approach…) 😉

---

<div class="post-metadata">

**Author:** ![tbreloff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbreloff/32/68_2.png) [@tbreloff](https://discourse.julialang.org/u/tbreloff)\
**Post date:** [February 23, 2017, 11:41am UTC](https://discourse.julialang.org/t/plots-multiple-groups-of-series-from-a-dataframe-seems-a-bug-in-plots/2246/3 "2017-02-23T11:41:25Z")

</div>

I responded to the issue (btw… don’t open an issue if you’re posting the  
question here)

Likely you’re misusing palette, which determines the family of colors.  
Colors are selected from the palette in an attempt to be distinguishable  
from each other. Instead just set the color directly.

---

<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 23, 2017, 1:16pm UTC](https://discourse.julialang.org/t/plots-multiple-groups-of-series-from-a-dataframe-seems-a-bug-in-plots/2246/4 "2017-02-23T13:16:44Z")

</div>

This is not a bug.  
The colors should be a row vector, as desribed here [https://juliaplots.github.io/input\_data/](https://juliaplots.github.io/input_data/) . And you need to specify `color`, not `color_palette`. EDIT: I now see that Tom responded the same on the issue.

```julia
mycolors = [:blue :red] # same with mycolors = [:yellow, :orange]
fruits_plot = plot(df, :year, :prod, group=:product, linestyle = :solid, linewidth=3, linecolor=:match, color = mycolors)
fruits_plot = plot!(df, :year, :cons, group=:product, linestyle = :dot, linewidth=3, linecolor=:match, color = mycolors)

```

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