Reputation: 739
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:
How do I display my labels ("one", "two", "three"), instead of "1 2 3" on the x axis?
Thanks!
Upvotes: 3
Views: 2148
Reputation: 6295
In the Plots
version v1.38.0
, one can do it by specifying the labels in the optional keyword argument xticks
:
data = [1,2,3]
labels = ["one","two","three"]
bar(
data,
legend=false,
xticks=(1:length(data), labels)
)
Upvotes: 0
Reputation: 739
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)
Upvotes: 3