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

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:


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:

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

1 Like

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 , you’ll see all of the things I’ve just described (in fact all possible kwargs - there are many!) under the “manual/attributes” tab.

1 Like

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?

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.

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

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.

No effect.

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

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.

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

1 Like

Thanks, that looks good enough, I think.

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

1 Like

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.