Search code examples
juliaplots.jl

How to change labels on the x axis of a bar plot from numbers to text?


I'm trying to make a bar plot using Plots.jl and the GR backend and wanted to ask how to make the x axis display text labels rather than numbers. Basically this is what I'm doing:

using Plots; gr()
data = [1,2,3]
labels = ["one","two","three"]

bar(data, legend=false)

This produces the following plot:

example bar plot

How do I display my labels ("one", "two", "three"), instead of "1 2 3" on the x axis?

Thanks!


Solution

  • The answer (thanks Tom!) is to pass the labels as x values (currently only possible on the dev branch):

    Pkg.checkout("Plots","dev")
    using Plots
    gr()
    
    data = [1,2,3]
    labels = ["one","two","three"]
    
    bar(labels, data, legend=false)