Search code examples
juliaheatmapaxisaxis-labelsmakie.jl

Makie in Julia: keeping my axis labels but hiding the tickmark numbers


I am trying to learn how to use Makie with Julia, I have only used Winston so far. I am making a graph with latitude and longitude axis, and I want just their values on the axis, not the standard 1,5, and 10 that makie puts on all their axis. I also want to have my axis labeled, but I cant figure out how to separate the two -- to get rid of the numbers and keep the words. I am doing this in jupyter notebook.

I am importing netcdf data with multidimensional variables. I have already isolated the depth variable to one dimension for this. I have tried:

using NetCDF
using CairoMakie
using ColorSchemes

fig, axis, p=heatmap(lon1, lat1, h; labels=true, colormap=:rainbow_bgyrm_35_85_c71_n256)
Colorbar(fig[:, end+1], p, label="meters")
ax=Axis(fig[1,1], ylabel ="latitiude", xlabel="longitude", title="depth map",
leftspinevisible=false, bottomspinevisible=false, ticklabelvisible=false)
ax.aspect = 0.5
colsize!(fig.layout, 1, Aspect(1, 0.5))
display(fig)

and the graph I get is this : (https://i.sstatic.net/N2Npi.png) on the axis' is my lat/long numbers, the makie axis numbers that I dont want, and the labels that I do want.

Note: I get exactly the same looking graph with and without the code leftspinevisible=false, bottomspinevisible=false, ticklabelvisible=false in my axis command.

Next I tried :

hidedecorations!.(ax)
display(fig)

Which only got rid of all the makie labels- both numbers and labels:(https://i.sstatic.net/rNTmf.png) I have also tried adding the condition: ticklabels=false in the hide decorations code, after 'ax', still in parenthesis.

I have also already read through the documentation for labels and axis manipulation on the Makie webpage.

How can I keep the x/y labels while getting rid of the other numbers?


Solution

  • You are seeing double ticks and labels because you are adding a new axis to the figure on top of the axis that is created when you call heatmap. To make modifications to the axis that you already created, you can write to the fields of the returned axis:

    using CairoMakie
    x = collect(1:10)
    y = collect(1:10)
    z = rand(10, 10)
    fig, axis, p = heatmap(x, y, z)
    
    axis.xlabel = "longitude"
    axis.ylabel = "latitude"
    axis.xticks = [2,3,5,7]
    axis.yticks = 1:2:10
    
    display(fig)
    

    Another option is to first create the axis with the properties you desire where you want it in a figure, then use the heatmap! method (with the exclamation mark) to draw the heatmap in that axis:

    using CairoMakie
    fig = Figure()
    axis = Axis(fig[1,1],
        xlabel = "longitude",
        ylabel = "latitude",
        xticks = [2,3,5,7],
        yticks = 1:2:10)
    
    x = 1:10
    y = 1:10
    z = rand(10, 10)
    heatmap!(axis, x, y, z)
    
    display(fig)
    

    These produce roughly the same figure:

    heatmap of 100 random random values in a 10x10 grid