Makie contours with NaN data: contour labels are on top of lines

Hello. I’ve recently switched from Plots.jl to Makie.jl and am having a problem with contour labels. My application is oceanographic, and my goal is to plot contours of ocean temperature versus a horizontal coordinate on the x axis and a depth coordinate on the y axis. Since the data come from a ship that cannot go through the ocean bottom, the data are NaN for those depth regions that are below the water. I find that the contour labels run on top of the contour lines.

I’m using Julia 1.12.7, with the following package versions.

  • GLMakie v0.13.15
  • Makie v0.24.15

I tried to make a simplified test case, as shown below, along with the plotted output. The left-hand panel, without the “bottom”, has well-labelled contours. However, the right-hand panel, with that “bottom” inserted, has labels that are on top of the contour lines.

Question: am I doing something wrong? (I am aware that I can get the results with Plots but I really am hoping to switch my work entirely to. Makie, because this lets me do some other types of plots that are needed in oceanographic work.)

Many thanks in advance.
Dan Kelley / Oceanography / Dalhousie University

# Demonstrate a problem with contour labelling data with NaN values
# Top panel: contoured field, with proper contour labels
# Bottom panel: contoured field (now with some NaN values), with improper contour labels
using GLMakie
f(x, y) = abs(sin(x) + cos(y))
bad(x, y) = (x - 2) > y
x = range(0, 5, length=50);
y = range(0, 5, length=50);
z = @. f(x', y);
isbad = @. bad(x', y);
zz = copy(z)
zz[isbad] .= NaN
fig = Figure()
contour(fig[1, 1], x, y, z', color=:black, labels=true)
contour(fig[1, 2], x, y, zz', color=:black, labels=true)
save("contour_bug.png", fig)