REPL crash from attempting a heatmap plot with a large dataset

I seemed to be up against a limit on the size of dataset that CairoMakie can handle. I am trying to plot a heatmap of a large spectrogram from DSP.jl. I’ve reduced the problem I’m having to a size issue. Oddly, I was not getting an error message…the REPL would just unceremoniously kill itself.

I can reproduce (on my system) with this:

using CairoMakie
using ColorSchemes

num = 20000
row = range(1, num)
col = range(1, num*3)
val = rand(1:1:5,num, num*3)

fig = Figure(resolution = (1800, 800), fontsize = 30)
ax = Axis(fig[1,1]; xlabel = "time", ylabel = "freq", title = "Insert clever title here")
hm = CairoMakie.heatmap!(row, col, val; colormap = Reverse(:Blues_9))
fig

However, if I reduce num to 15,000, then I get this error message:

Error showing value of type Figure:
ERROR: Cairo stops rendering images bigger than 32745, which is likely a bug in Cairo. Please resample your image/heatmap with e.g. `ImageTransformations.imresize`

If I reduce the value of num to 10,000, then I get a heatmap.

I see I will need to downsample, but is the due to CairoMakie or my machine’s memory? Why error at some level and at a higher level, the REPL just crashes?

Is there some way to downsample only the y axis (freq) but keep the x (time) axis intact, perhaps with a scroll bar?

Thanks!

We found this value by trial and error in Cairo, which doesn’t throw any error and doesn’t mention this behavior in the docs…
You can use Images.imresize(val, (xres, yres)) for downsampling… Or something like that

1 Like

Would it be an option to switch to GLMakie for this?

GLMakie also has limits by the GPU for the heatmap size, they may even be smaller, depending on the gpu vendor…
This is currently the best bet:Frequently Asked Questions · Makie
:sweat_smile:

2 Likes