-
-
Notifications
You must be signed in to change notification settings - Fork 321
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: heatmap that can handle irregular rectilinear grids #675
Comments
Gentle bump! |
Right now your best bet is |
Here's a solution using using GeometryBasics
xs = tan.(atan(-3):0.1:atan(3))
ys = -2.5:0.1:2.5 |> collect
peaks(x,y) = 3*(1-x)^2 * exp(-(x^2) - (y+1)^2) - 10*(x/5 - x^3 - y^5) * exp(-x^2-y^2) - 1/3*exp(-(x+1)^2 - y^2)
zs = [peaks(x,y) for x in xs, y in ys]
# Needs to be a mesh to not get centered?
m = Rect2D(Point2f0(0.0), Vec2f0(1)) |> normal_mesh
# midpoints
midxs = 0.5(xs[1:end-1] .+ xs[2:end])
midys = 0.5(ys[1:end-1] .+ ys[2:end])
# Padding for outer rectangles
midxs = [2xs[1] - midxs[1]; midxs; 2xs[end] - midxs[end]]
midys = [2ys[1] - midys[1]; midys; 2ys[end] - midys[end]]
# rectangle position & size
pos = [Point2f0(x, y) for x in midxs[1:end-1] for y in midys[1:end-1]]
sizes = [Vec2f0(midxs[i+1] - midxs[i], midys[j+1] - midys[j]) for i in eachindex(xs) for j in eachindex(ys)]
# zs need transpose to match previous result
s = meshscatter(pos, markersize=sizes, marker=m, color=zs'[:], shading=false)
display(s) Btw, while making this I noticed that |
Maybe I can try to contribute, but I have no idea where I should start... Could you point me to where I could edit |
The "low effort" change would be to change the heatmap recipe here to be the meshscatter thing. The "high effort" change would be to adjust how GLMakie handles heatmaps (and I guess other backends as well). For that you probably need to change the draw_atomic function, add new |
Ha! I guess it's way more complicated than I anticipated. So the issue is in the backends, e.g., GLMakie, which applies Anyway, I am personally more interested in CairoMakie (to save to vectorized PDF) and I am hoping that maybe there is less work with it than with GLMakie. Please let me know if I'm wrong, but it seems like this |
Yea, I can look into making the changes in GLMakie. |
Oh yea - shouldn't the tiles of a heatmap be centered around their respective coordinates? I did this in the meshscatter version, but it's not the case in the for just |
fixed in JuliaPlots/GLMakie.jl#137 |
MWE:
outputs
The issue is that the irregular grid is replaced with a regular one. (You can see that the boxes in the
x
direction are regularly spaced, but they should not, sincex = tan.(atan(-3):0.1:atan(3))
.) I think the bug is that somewhere in the pipeline,x
is converted to a range (a(min, max)
tuple I think) and the irregularly spacedx
values are lost. It seemssurface
can handle these, so I'm hoping there is not too much work required to allow irregular grids withheatmap
, too! 🙂The text was updated successfully, but these errors were encountered: