Plots.jl: Specify text labels for xticks and yticks

Created on 16 Feb 2016  Â·  6Comments  Â·  Source: JuliaPlots/Plots.jl

Is it possible to place text instead of numbers for x and y ticks? Currently the definition is xticks!{T<:Real}(v::AVec{T}). Or is there another command I have missed?

Most helpful comment

Ok finally in front of a computer. There are a few things here, and I made some fixes in the dev branch. (do Pkg.checkout("Plots","dev"))

  • Plots would accept only "tick values" or "tick values and labels"... it wouldn't accept "tick labels". I added this.
  • The Gadfly backend was missing a collect around the tick values when passing "values and labels"... fixed.
  • The PyPlot backend was missing a call to set_xticklabels and incorrectly was trying to pass both values and labels to set_xticks

After these changes, PyPlot works as expected, and Gadfly/Plotly will work in this example, but will fail generally due to weirdness I don't want to go into (values are indices, not values). Stick with PyPlot if you can. This should work for you:

using Plots; pyplot()
x = 0:2:4
s = ["Isn't", "Plots", "Great??"]
subplot(
    plot(rand(3), xticks = x),
    plot(rand(3), xticks = s),
    plot(rand(3), xticks = (x,s))
)

All 6 comments

You should be able to pass a tuple of (abstractvector of tick numbers, abstractvector of tick labels). It might not work on all backends, but test on Gadfly to start.

I don't know if this work with the "xticks!" function... Call "plot!"

Yes documentation needs an overhaul... Its in the works.

On Feb 16, 2016, at 5:58 AM, Robert Luke [email protected] wrote:

Is it possible to place text instead of numbers for x and y ticks? Currently the definition is xticks!{T<:Real}(v::AVec{T}). Or is there another command I have missed?

—
Reply to this email directly or view it on GitHub.

Thanks for the help.

I included the command p = plot!(yticks=(vec(1:length(channels)), channels)) where typeof(channels) = Array{AbstractString,1}

In PyPlot I get no change in tick labels. And I get an inexact error in gadfly. Any advice on what I am doing wrong would be appreciated.

... and on the documentation Im happy to help. Is it hosted in a different repo?

ERROR: LoadError: InexactError()
 in copy! at abstractarray.jl:310
 in discretize_make_pda at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:308
 in discretize at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:353
 in discretize at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:342
 in apply_scale at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:427
 in apply_scales at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:39
 in apply_scales at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:59
 in render_prepare at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:652
 in render at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:718
 in display at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:952
 [inlined code] from multimedia.jl:151
 in display at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:900
 in display at /Users/rluke/.julia/v0.4/Plots/src/output.jl:114
 in display at REPL.jl:117
 [inlined code] from multimedia.jl:151
 in display at multimedia.jl:162
 in include at /Applications/Julia-0.4.3.app/Contents/Resources/julia/lib/julia/sys.dylib
 in include_from_node1 at /Applications/Julia-0.4.3.app/Contents/Resources/julia/lib/julia/sys.dylib
while loading /Users/rluke/.julia/v0.4/EEG/test/plotting/plots.jl, in expression starting on line 21

Ok if you can't figure it out I'll check it out later when I'm in front of a computer.

On Feb 16, 2016, at 8:54 AM, Robert Luke [email protected] wrote:

Thanks for the help.

I included the command p = plot!(yticks=(vec(1:length(channels)), channels)) where typeof(channels) = Array{AbstractString,1}

In PyPlot I get no change in tick labels. And I get an inexact error in gadfly. In advice would be appreciated.

... and on the documentation Im happy to help. Is it hosted in a different repo?

ERROR: LoadError: InexactError()
in copy! at abstractarray.jl:310
in discretize_make_pda at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:308
in discretize at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:353
in discretize at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:342
in apply_scale at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:427
in apply_scales at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:39
in apply_scales at /Users/rluke/.julia/v0.4/Gadfly/src/scale.jl:59
in render_prepare at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:652
in render at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:718
in display at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:952
[inlined code] from multimedia.jl:151
in display at /Users/rluke/.julia/v0.4/Gadfly/src/Gadfly.jl:900
in display at /Users/rluke/.julia/v0.4/Plots/src/output.jl:114
in display at REPL.jl:117
[inlined code] from multimedia.jl:151
in display at multimedia.jl:162
in include at /Applications/Julia-0.4.3.app/Contents/Resources/julia/lib/julia/sys.dylib
in include_from_node1 at /Applications/Julia-0.4.3.app/Contents/Resources/julia/lib/julia/sys.dylib
while loading /Users/rluke/.julia/v0.4/EEG/test/plotting/plots.jl, in expression starting on line 21
—
Reply to this email directly or view it on GitHub.

@codles the documentation is hosted in ExamplePlots.jl

Ok finally in front of a computer. There are a few things here, and I made some fixes in the dev branch. (do Pkg.checkout("Plots","dev"))

  • Plots would accept only "tick values" or "tick values and labels"... it wouldn't accept "tick labels". I added this.
  • The Gadfly backend was missing a collect around the tick values when passing "values and labels"... fixed.
  • The PyPlot backend was missing a call to set_xticklabels and incorrectly was trying to pass both values and labels to set_xticks

After these changes, PyPlot works as expected, and Gadfly/Plotly will work in this example, but will fail generally due to weirdness I don't want to go into (values are indices, not values). Stick with PyPlot if you can. This should work for you:

using Plots; pyplot()
x = 0:2:4
s = ["Isn't", "Plots", "Great??"]
subplot(
    plot(rand(3), xticks = x),
    plot(rand(3), xticks = s),
    plot(rand(3), xticks = (x,s))
)

Thanks, the dev branch worked with pyplot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apalugniok picture apalugniok  Â·  3Comments

crstnbr picture crstnbr  Â·  3Comments

pkofod picture pkofod  Â·  3Comments

Krastanov picture Krastanov  Â·  3Comments

jebej picture jebej  Â·  4Comments