Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: nan_color kwarg for meshscatter #720

Closed
briochemc opened this issue Oct 13, 2020 · 9 comments
Closed

Feature request: nan_color kwarg for meshscatter #720

briochemc opened this issue Oct 13, 2020 · 9 comments

Comments

@briochemc
Copy link
Contributor

It would be great to be able to use the nan_color kwarg as implemented for heatmap by @jkrumbiegel in response to #666.

This would allow it to be combined with a meshscatter recipe for irregularly spaced grids (inspired from @ffreyer in #675 (comment)), something like that:

using GeometryBasics
@recipe(EdgyHeatMap, ex, ey, z) do scene
    Attributes(
        nan_color=:lightgray,
    )
end
# What the recipe actually does
midpoints(x) = 0.5(x[1:end-1] .+ x[2:end])
positions(ex, ey) = [Point2f0(x, y) for x in ex[1:end-1] for y in ey[1:end-1]]
sizes(dxs,dys) = [Vec2f0(dx, dy) for dx in dxs for dy in dys]
mycolors(z) = z[:]
function AbstractPlotting.plot!(p::EdgyHeatMap)
    ex = p[:ex]
    ey = p[:ey]
    z = p[:z]
    # Needs to be a mesh to not get centered?
    m = Rect2D(Point2f0(0.0), Vec2f0(1)) |> normal_mesh
    # midpoints
    midxs = lift(midpoints, ex)
    midys = lift(midpoints, ey)
    # rectangle position & size
    pos = lift(positions, ex, ey)
    dxs = lift(diff, ex)
    dys = lift(diff, ey)
    sizs = lift(sizes, dxs, dys)
    # z needs to be transposed
    Z = lift(mycolors, z)
    meshscatter!(p, pos, markersize=sizs, marker=m, color=Z, shading=false)
    p
end

and plot nice stuff like this:

test

but with gray NaNs! 😄

@Alexander-Barth
Copy link

@briochemc I am wondering if this PR could help in your case. (But note the PR only modifies the behavior of heatmap when using matrices as X and Y).

JuliaPlots/CairoMakie.jl#177

@briochemc
Copy link
Contributor Author

I actually don't need this anymore since Makie's heatmap started accepting irregularly spaced (rectilinear) grids, but your PR looks really cool and I'm sure I would use it at some point, too!

@Alexander-Barth
Copy link

Maybe I misunderstand the present issue, but if you want to use grey NaNs you could do this: (with PR JuliaPlots/CairoMakie.jl#177)

using CairoMakie
x = sqrt.(0:10:100); y = sqrt.(0:10:100);
X = [x_ for x_ in x,  y_ in y]
Y = [y_ for x_ in x,  y_ in y]
A = randn(10,10); 
A[3,5] = NaN; 
fig = heatmap(X,Y,A, nan_color = RGBf0(0.8,0.8,0.8));
save("test.png",fig)

test

@SimonDanisch
Copy link
Member

The thing is, you can do that with the current Makie already, with the new irregular grid heatmaps:

using CairoMakie
x = sqrt.(0:10:100); y = sqrt.(0:10:100);
A = randn(10,10); 
A[3,5] = NaN; 
heatmap(x,y,A, nan_color = RGBf0(0.8,0.8,0.8))

image

@Alexander-Barth
Copy link

Thanks @SimonDanisch , I did not know that 😄 Sorry for the noise.

@SimonDanisch
Copy link
Member

btw surface also already supports matrices as arguments ;) Just needs shading false and z set to all 0, to generate that kind of heatmap..Although it will be interpolated ;)

@Alexander-Barth
Copy link

Indeed surface is pretty flexible. In our case, we can have quite a few NaNs and it would be good to avoid them to spread spatially (I can give you some examples if this would be helpful). Would you consider a PR which implements the non-interpolated option for surface ?

@asinghvi17
Copy link
Member

A non-interpolated surface would basically be a generated mesh, with unique vertices for each grid cell. This is the only way to get per-face color into OpenGL, unfortunately.

We could have a short path for CairoMakie though!

@SimonDanisch
Copy link
Member

nan_color is part of meshscatter these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants