MakieOrg / Makie.jl

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

CairoMakie heatmap pixels overlap #3619

Open maxfreu opened 8 months ago

maxfreu commented 8 months ago

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

jkrumbiegel commented 8 months ago

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.

maxfreu commented 8 months ago

https://github.com/MakieOrg/Makie.jl/blob/f92b2607de3788a6c2b45eb5fd5546fb634fab3a/CairoMakie/src/primitives.jl#L785-L795

here, right?