MakieOrg / Makie.jl

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

Irregular semi-transparent gradients with CairoMakie #841

Open sfmiller940 opened 3 years ago

sfmiller940 commented 3 years ago

I’ve been trying to make heatmaps using colormaps that go from transparent to either white or black.

The interpolation works as expected for black but it looks terrible for white.

Here’s some sample code with the result:

using CairoMakie, Plots.Colors

xs = LinRange(0, 10, 100)
ys = LinRange(0,10, 100)
zs = [x+im*y for x in xs, y in ys]
rings = abs.(zs) .% 3

fig = Figure();
ax1 = fig[1, 1] = Axis( fig, backgroundcolor="blue");
ax2 = fig[2, 1] = Axis( fig, backgroundcolor="blue");

cmblack = cgrad(range(HSLA(0,0,0,0), stop=HSLA(0,0,0,1), length=100));
CairoMakie.heatmap!(ax1, xs, ys, rings, colormap=cmblack, interpolate=true);

cmwhite = cgrad(range(HSLA(0,0,1,0), stop=HSLA(0,0,1,1), length=100));
CairoMakie.heatmap!(ax2, xs, ys, rings, colormap=cmwhite, interpolate=true);

fig

Screenshot from Juno:

interpolation

Saved PNG:

interpol

I noticed the comment "Set filter doesn't work!?" in src/primitives.jl, so maybe this is a known issue? I'll try to investigate more in case I can help...

jkrumbiegel commented 3 years ago

really weird, I've tried tracing this until the point where the cairo surface is created, and it seems like the values there are correct. But both svg and png display with the white colormap are then buggy. Maybe a Cairo issue? It seems to me we're passing correct data to it

jkrumbiegel commented 3 years ago

oh and the filter thing relates to the fact that the collection of filters cairo offers sometimes don't do anything depending on svg or png or pdf export. for example nearest interpolation for heatmaps doesn't work in svg etc.