Removing numeric labels from axis

I fear this might be a stupid question . . . but, how does one remove the numeric labels from an axis in a plot?

I searched the documentation

but didn’t find an option. (It’s entirely possible that I’m missing it, though.)

In the following example, I’d like to remove the numeric labels “-4”, “-2”, “0”, etc. from the y axis, leaving the tick marks and grid lines intact.

using Plots
plot(100:100:300, hcat([1, 2, 4], [-1,-2,-4]))

For my actual plot, I’d like to do this because only the relative amplitudes of the curves matter.

This is just a hack…

plot(100:100:300, hcat([1, 2, 4], [-1,-2,-4]), xtickfontcolor=:white)

Another way:

 plot(1:3, [[1, 2, 4] [-1,-2,-4]], xformatter=_->"")

Should be fixed by add `:none` formatter by t-bltg · Pull Request #4483 · JuliaPlots/Plots.jl · GitHub.


@t-bltg, excellent. In which version of Plots.jl will this fix be available so that we can start using it?

1.35.6 or 1.35.7.

1 Like

@t-bltg, thanks, it works in v1.35.7 for the above examples with keyword xformatter = :none.

However, I can’t get it to work inside a plot recipe together with ticks := :native, which is key when zooming linked subplots.

Hum, can you post a MRE ?

Also, on which backend ?

@t-bltg, thanks.
Please find MWE below using the pyplot() backend.

The problem is to have multiple linked subplots, have only one y-scale on the left, be able to zoom-in with ticks = :native and keep the y-grid lines synchronized.

Notice how the y-grid lines are out of sync (the bottom figure is a zoom-in of the top one):

using Measures, Plots; pyplot()

mutable struct MyMatrix

@recipe function f(MM::MyMatrix)
    seriestype := :path
    link := :y
    yflip := true
    framestyle := :box
    n = size(MM.M,2)
    layout := (1, n-1)
    for i in 2:n
        @series begin
            ylabel := nothing
            subplot := i-1
            (i==2) && (yaxis := "Y-axes [unit]")
            (i==2) && (ticks := :native)
            (i>2) && (yformatter := :none)
            leftmargin := (i==2) ? 5mm : -15mm 
            MM.M[:,i], MM.M[:,1]

n = 1000
x = range(0,20,n)
MM = MyMatrix(Matrix{Float64}(undef,n,3))
MM.M[:,1] .= x
MM.M[:,2] .= sin.(x)
MM.M[:,3] .= 4*cos.(x)

Thanks, the issues appears on the first image, the ticks are out of sync.
This is because we use get_shared_y_axes().join(...) in the PyPlot backend.
It looks like we have to set the ticks manually, as hinted in python - How to share x axes of two subplots after they have been created - Stack Overflow.

It won’t work with zoom in and zoom out, will it?

Note that if we keep the y-labels on each linked subplot and use ticks = :native, then everything is in-sync, including during zoom-in. But then the plot looks ugly with all the y-labels repeated in all subplots…

Nevermind, using selective transparency is an effective workaround: ytickfontcolor = RGBA(0,0,0,0)

It looks like using sharex or sharey allows sync when zooming: ax != y_ax_link && ax."sharey"(y_ax_link), but it makes y ticks labels appear twice …


Would this be acceptable ?

1 Like

As indicated in my previous post (edited), good results can be obtained using: ytickfontcolor = RGBA(0,0,0,0), in addition to link = :y and ticks = :native. Thank you.

1 Like