# How to move the legend around in a groupedbar plot and make the bars black and white

**URL:** https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516
**Category:** Visualization
**Created:** [September 4, 2018, 6:12am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516 "2018-09-04T06:12:22Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [September 4, 2018, 6:12am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/1 "2018-09-04T06:12:22Z")

</div>

So I am trying to draw a grouped bar chart with the legend on the top right corner but not overlapping the chart. The closest thing to what I want is the `groupedbar` from `StatPlots`. The problem is that currently the chart is covered by the legend as such:

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

I also want the bars to be black and white not colored. I couldn’t find enough bar chart examples, and I am not sure how to explore all the valid kwargs in a function. Any help or alternative is appreciated, also general tips on how to find my way around Julia’s plotting ecosystem.

Here is the code to generate this on v0.6.4:

```julia
using StatPlots

alg_names = ["SIMP", "CSIMP", "DT-CSIMP", "DT-CSIMP-Reuse", "Step-ASIMP", "ASIMP"]
nalgs = length(alg_names)
prob_names = ["Cantilever", "Half MBB", "L Beam", "Tie Beam"]
nprobs = length(prob_names)

ctg = repeat(alg_names, inner = nprobs)
nam = repeat(prob_names, outer = nalgs)
groupedbar(nam, rand(nprobs, nalgs), group = ctg, xlabel = "Problems", ylabel = "FEA Simulations",
        title = "Number of simulations", bar_width = 0.67,
        lw = 0, framestyle = :box, legend=:topright)

```

adapted from [GitHub - JuliaPlots/StatsPlots.jl: Statistical plotting recipes for Plots.jl](https://github.com/JuliaPlots/StatPlots.jl#grouped-bar-plots).

---

<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: [September 4, 2018, 7:55am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/2 "2018-09-04T07:55:47Z")

</div>

You can change the legend position by `legend = :topleft` but I think what you need here is the plotting area to have a bigger extent `ylim = (0,1.2)`. To get black and white bars delete your `lw = 0` (`lw` is `linewidth`; or set it to `0.5`) and set `fillcolor = :white`. Note that if you’re in black and white you won’t be able to use the color legend, and should perhaps just set `legend = false`. In general the Plots ecosystem (RecipesBase, PlotUtils, PlotThemes, StatPlots and PlotRecipes) is documented at [https://docs.juliaplots.org](https://docs.juliaplots.org) , you’ll see all of the things I’ve just described (in fact all possible kwargs - there are many!) under the “manual/attributes” tab.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [September 4, 2018, 11:01am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/3 "2018-09-04T11:01:52Z")

</div>

Thanks for your response and the pointer. But what I meant by black and white is that they should still be distinguishable so using different patterns instead of different colors. Is this possible?

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [September 4, 2018, 11:08am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/4 "2018-09-04T11:08:16Z")

</div>

I think you’re looking for the `style` keyword with one of these options: `[:auto,:solid,:dash,:dot,:dashdot,:dashdotdot]`. The default is `:solid`.

See [here](http://docs.juliaplots.org/latest/attributes/#series).

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [September 4, 2018, 11:20am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/5 "2018-09-04T11:20:42Z")

</div>

This is for the boundary of the box though not the filling.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/b/cbfaa7ae82bcb503d46783650375894b47f9f0d6.png)

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [September 4, 2018, 11:24am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/6 "2018-09-04T11:24:54Z")

</div>

Right, my bad - from my quick glance over the documentation, I can’t find anything specifying the fill pattern though. Have you set a color (e.g. black) for the plot you just tried? It might be that combining these two can achieve what you’re looking for. Is there a specific reason why you want them to be black and white instead of colored or grayscale?

In theory, Plots should be able to do all the things your chosen backend supports. I’m not an expert using Plots and its various backends though.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [September 4, 2018, 11:42am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/7 "2018-09-04T11:42:45Z")

</div>

> [@Sukera](#):
>
> Have you set a color (e.g. black) for the plot you just tried? It might be that combining these two can achieve what you’re looking for.

No effect.

> [@Sukera](#):
>
> Is there a specific reason why you want them to be black and white instead of colored or grayscale?

Yes to make the plot meaningful if printed in black only, no colors.

---

<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: [September 4, 2018, 12:56pm UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/8 "2018-09-04T12:56:14Z")

</div>

There are no greyscale pattern fills in Plots, unfortunately. I know some (few) newspapers and even some scientific journals still only print black and white, so it would be a useful thing to have. If some of the backends (like GR or PyPlot) supports this natively it should be fairly easy to add support.

---

<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: [September 4, 2018, 12:57pm UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/9 "2018-09-04T12:57:16Z")

</div>

Until then you can do `palette = :greys` to get different shades of grey.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [September 4, 2018, 1:05pm UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/10 "2018-09-04T13:05:56Z")

</div>

Thanks, that looks good enough, I think.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/4/84439c49fb9df2aa3c798b4a3dd423b504a61ae1.png)

---

<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: [September 4, 2018, 1:19pm UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/11 "2018-09-04T13:19:21Z")

</div>

You can use a hack to get the colors sequential. But here it’s possibly better that it’s not.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [September 9, 2018, 5:06am UTC](https://discourse.julialang.org/t/how-to-move-the-legend-around-in-a-groupedbar-plot-and-make-the-bars-black-and-white/14516/12 "2018-09-09T05:06:36Z")

</div>

I wonder, is there a way to make the plot respect the order of the bars given in `group` kwarg, e.g. SIMP then CSIMP, etc.? It seems to alphabetically order them.
