Search code examples
juliaplots.jl

How to change bar plot orientation in Plots.jl


When I try this:

using Plots

bar(["a", "b", "c"], [5, 9, 7]; legend=false, orientation=:h)

I get this (not desired result as you can see):

result

How to properly change the bar plot orientation in Plots.jl in Julia?

Thank you!


Solution

  • A few options:

    1. (simplest) Remove orientation=:h
    2. Use orientation=:v:
    bar(["a", "b", "c"], [5, 9, 7]; legend=false, orientation=:v)
    

    enter image description here

    The documentation says this is deprecated. The alternative now is:

    1. Use permute instead:
    bar(["a", "b", "c"], [5, 9, 7]; legend=false, permute = (:x, :y)) # This doesn't work in this case, as regardless of the order we get the horizontal version. If you were wanting to make it horizontal, this is what you would do now.
    

    More info: Plots.jl documentation page.