Plots.jl - Strings as xticks


#1

I want to replace the xticks with strings. How can I do that? When I run :

using Plots

xticks = ["$i" for i in 1:10]
plot(rand(10), xticks=xticks)

I get an error:

Julia Client – Internal Error
MethodError: no method matching isless(::Float64, ::String)
Closest candidates are:
  isless(::Float64, !Matched::Float64) at float.jl:459
  isless(!Matched::Missing, ::Any) at missing.jl:70
  isless(::AbstractFloat, !Matched::AbstractFloat) at operators.jl:148
  ...
<(::Float64, ::String) at operators.jl:260
<=(::Float64, ::String) at operators.jl:309
(::getfield(Plots, Symbol("##110#111")){Float64,Float64})(::String) at axes.jl:207
mapfilter(::getfield(Plots, Symbol("##110#111")){Float64,Float64}, ::typeof(push!), ::Array{String,1}, ::Array{String,1}) at abstractset.jl:340
filter(::Function, ::Array{String,1}) at array.jl:2351
optimal_ticks_and_labels(::Plots.Axis, ::Array{String,1}) at axes.jl:207
get_ticks(::Plots.Axis) at axes.jl:272
axis_drawing_info(::Plots.Subplot{Plots.GRBackend}) at axes.jl:591
_update_min_padding!(::Plots.Subplot{Plots.GRBackend}) at gr.jl:584
iterate at generator.jl:47 [inlined]
_collect(::Array{AbstractLayout,2}, ::Base.Generator{Array{AbstractLayout,2},typeof(Plots._update_min_padding!)}, ::Base.EltypeUnknown, ::Base.HasShape{2}) at array.jl:619
collect_similar at array.jl:548 [inlined]
map at abstractarray.jl:2018 [inlined]

#2

Try xticks = (1:10, xticks). Not at a computer to confirm, but I’m 80% sure that’s it. It does live in the docs somewhere, I’ve gone looking for it on numerous occasions.


#3

This is correct - plot(rand(10), xticks = (1:10, string.(1:10)) should do what your example was trying to do.


#4

Thanks that works!