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

CairoMakie heatmap pixels overlap #3619

Open
maxfreu opened this issue Feb 9, 2024 · 2 comments · May be fixed by #3625
Open

CairoMakie heatmap pixels overlap #3619

maxfreu opened this issue Feb 9, 2024 · 2 comments · May be fixed by #3625
Labels
bug CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo.

Comments

@maxfreu
Copy link

maxfreu commented Feb 9, 2024

I want to create a heatmap of a non-square matrix with square pixels. I'm trying to achieve this by setting a colsize of defined aspect. This however leads to somehow staggered pixels and strange effects, as CairoMakie seemingly draws the pixels larger than they actually are.

Some demo code and the corresponding PDF opened in inkscape:

fig = Figure(size = mm2pt.((83, 50)))
ax = Axis(fig[1, 1])
r = rand(20,30)
colsize!(fig.layout, 1, Aspect(1, size(r)[1] / size(r)[2]))
heatmap!(ax, r; colorrange = (0, 1))
save("deleteme.pdf", fig)

Screenshot from 2024-02-09 17-10-58

The problem:

Screenshot from 2024-02-09 17-27-21

Any idea how I can make the pixels square without this effect?

Makie 0.20.7, CairoMakie 0.11.8, julia 1.10

@maxfreu maxfreu added the bug label Feb 9, 2024
@jkrumbiegel
Copy link
Collaborator

jkrumbiegel commented Feb 9, 2024

CairoMakie draws heatmap cells larger than they are so that you don't get background-colored artifacts at the seams. It should not draw them larger if the adjacent cells are not fully opaque, but maybe in your case the cells are even spanning across more than one neighbor, so they peek through. So we have to check that the overdrawing width is at most some fraction of the neighboring cell so that this cannot happen.

@asinghvi17 asinghvi17 added the CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo. label Feb 9, 2024
@maxfreu
Copy link
Author

maxfreu commented Feb 11, 2024

if alpha(colors[i, j]) == 1
# sign.(p - center) gives the direction in which we need to
# extend the polygon. (Which may change due to rotations in the
# model matrix.) (i!=1) etc is used to avoid increasing the
# outer extent of the heatmap.
center = 0.25f0 * (p1 + p2 + p3 + p4)
p1 += sign.(p1 - center) .* Point2f(0.5f0 * (i!=1), 0.5f0 * (j!=1))
p2 += sign.(p2 - center) .* Point2f(0.5f0 * (i!=ni), 0.5f0 * (j!=1))
p3 += sign.(p3 - center) .* Point2f(0.5f0 * (i!=ni), 0.5f0 * (j!=nj))
p4 += sign.(p4 - center) .* Point2f(0.5f0 * (i!=1), 0.5f0 * (j!=nj))
end

here, right?

@maxfreu maxfreu linked a pull request Feb 12, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants