I’m new to Julia and have been toying around with Makie to move some of my plotting from R/ggplot to Julia/Makie, which has been a pleasure so far. However, I’ve been having an issue which I believe to be illustrated by the following example:
using GLMakie
fig = Figure()
ax = Axis(fig[1, 1])
x = (0.1:0.1:10) .+ 1e7
y = 1:100
scatter!(ax, x, y)
save("example.png", fig)
The saved plot, as well as the one I see interactively, is shown below:
I would’ve expected a straight line of points, which is also what I see if I don’t add 1e7 to the xs. I’m sadly not familiar enough with Julia/Makie to be sure what’s going on here.
This seems like a bug to me, presumably in the system that translates values of x into positions on the screen. To me, the most convincing thing is making clear that numeric precision issues in the data aren’t involved at all by rescaling x back down again:
fig = Figure()
ax = Axis(fig[1, 1])
x = (collect(0.1:0.1:10) .+ 1e7) .- 1e7
y = 1:100
scatter!(ax, x, y)
For some reason I don’t understand, I can’t get Debugger.jl to work with this code, so I couldn’t figure out quickly where things are getting overly quantized.
All numerical data in Makie is internally translated to Float32 before being plotted. For scatter plots this happens here for example (Point2f0 is 32-bit precision).
From what I understand, the rationale is that GPU-based backends need the data to be in Float32 for performance reason, but this does create some problems in a few cases. For example, converting date times to milliseconds is another scenario where this introduces some annoyances.
I imagine that ideally the conversion to Float32 should not happen in backend-independent code (as it currently does) and the GPU backends should be somehow find a way to use the whole Float32 range for the plot by shifting data back and forth, but have no idea how feasible this is.