# How to change the background colour of \`fillstyle\`?

**URL:** https://discourse.julialang.org/t/how-to-change-the-background-colour-of-fillstyle/117815
**Category:** Visualization
**Tags:** statsplots
**Created:** [August 4, 2024, 4:42pm UTC](https://discourse.julialang.org/t/how-to-change-the-background-colour-of-fillstyle/117815 "2024-08-04T16:42:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![chuljang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chuljang/32/6608_2.png) [@chuljang](https://discourse.julialang.org/u/chuljang)
#### Post date: [August 4, 2024, 4:42pm UTC](https://discourse.julialang.org/t/how-to-change-the-background-colour-of-fillstyle/117815/1 "2024-08-04T16:42:35Z")

</div>

With the `StatsPlots` package (not with `Makie` or other packages), I would like to change the background colour of `fillstyle`, where it has `:+`, `:|`, and etc. Is there any way? Alternatively, I wrote the following code which draw two overlapping bar graphs, but the problem is I cannot change the fillings in legend.

```Julia
  using StatsPlots
  gr()
  
  bar_group = 1:3
  bar_data = [rand(3) rand(3) rand(3) rand(3) rand(3) rand(3) rand(3) rand(3) rand(3)]
  
  gb = groupedbar(bar_group, bar_data, bar_position =:stack, bar_width = 0.5, 
      label=["item1" "item2" "item3" "item4" "item5" "item6" "item7" "item8" "item9"],
      fillcolor=[:black :darkgray :lightgray :black :darkgray :lightgray :black :darkgray :lightgray])
  groupedbar!(bar_group, bar_data, bar_position =:stack, bar_width = 0.5, label=false,
      fillcolor=:black, fillalpha=0.5, fillstyle=[nothing nothing nothing :| :- :+ :/ :\ :x])
  
  plot!(legend=:outerbottom, legendcolumns=3, legend_font_halign=:right)

display(gb) 

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [August 5, 2024, 12:04pm UTC](https://discourse.julialang.org/t/how-to-change-the-background-colour-of-fillstyle/117815/2 "2024-08-05T12:04:04Z")

</div>

By using the fill style first, then overlaying the grayscale background fill on top using a bit of alpha transparency, you can get something like this:

 ![Plots_StatsPlots_groupedbar_fillstyle_background](https://global.discourse-cdn.com/julialang/original/3X/2/d/2db814d35589e72ce44327ffba344a0b80dd7b90.png)

However, the background color won’t appear in the legend for the filled-style items.

---

<div class="post-metadata">

### Author: ![chuljang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chuljang/32/6608_2.png) [@chuljang](https://discourse.julialang.org/u/chuljang)
#### Post date: [August 6, 2024, 9:02am UTC](https://discourse.julialang.org/t/how-to-change-the-background-colour-of-fillstyle/117815/3 "2024-08-06T09:02:56Z")

</div>

Thank Rafael for your suggestion. It is worth trying. I hope that in later version, the `fillstyle` has more optional arguments, like `( :/, linecolor, backcolor)`, so the legend items are also automatically updated.
