MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 310 forks source link

`nan_color` do not work as expected for `surface!` #4524

Open ph-kev opened 2 days ago

ph-kev commented 2 days ago

I am using Makie v0.21.14

I can reproduce the bug with a fresh environment. The bug is that nan_color do not work as expected. I would expect the color of the NaN to be red and not transparent.

using CairoMakie

lons = -180:180
lats = -90:90
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]

field[1:100,1:100] .= NaN

fig = Figure()
ax = Axis(fig[1,1])
surface!(ax, lons, lats, field; shading = NoShading, nan_color = :red)
fig

The code above produce the plot below.

Image

asinghvi17 commented 2 days ago

Can confirm this is a bug, but only on CairoMakie (not GLMakie)

asinghvi17 commented 2 days ago

Strangely enough, I can't replicate this with mesh - it seems to be an issue specific to surface.

Mesh example:

using CairoMakie
vertices = [
    0.0 0.0 0.0;
    1.0 0.0 0.0;
    1.0 1.0 0.0;
    0.0 1.0 0.1;
] # points are 3D to make sure this goes through `draw_mesh3d`

faces = [
    1 2 3;
    3 4 1;
]

colors = [1.0, 2.0, 3.0, NaN]

scene = mesh(vertices, faces, color = colors, shading = NoShading, nan_color = :red)

Image

Surface example:

using CairoMakie
surface([1.0 2.0 3.0 4.0 5.0; 3.0 4.0 NaN 4.0 5.0; 1.0 2.0 3.0 4.0 5.0] ./ 10; nan_color = :red)

Image

so clearly something fishy is going on here.