Different outputs after adding x-axis coordinates of data in Makie.jl

The outputs are different for the codes below:

f = Figure()
ax1 = Axis(f[1, 1], xgridvisible=false, ygridvisible=false)
scatter!(ax1, 0:1e-3:1, ones(1001), markersize=1)
f

f = Figure()
ax1 = Axis(f[1, 1], xgridvisible=false, ygridvisible=false)
scatter!(ax1, 60000 .+(0:1e-3:1), ones(1001), markersize=1)
f


Is it a bug?

Yes and no. It’s quantization due to your data being converted to Float32s in Makie’s internals. They don’t have enough precision to resolve small ranges around larger values like 60000 ± 1e-3 compared to 0 ± 1e-3.

It’s an old issue in Makie that stems from GLMakie needing to convert everything to Float32 to be appropriate for GPUs. The annoying thing is that it mostly doesn’t matter for visual outputs but sometimes it does like you show here.

There are some efforts underway to improve the situation, for example by feeding Float64 through unconverted in CairoMakie.

1 Like

How to do it? I have used CairoMakie.jl, and modified the above code:

scatter!(ax1, Float64.(60000 .+(0:1e-3:1)), ones(1001), markersize=1)

The outputs are still different.

The are underway but not merged yet. For now you have to do what you already did in your example with the range around 0 and use less problematic input data (closer around 0). Not really a way around it. (The same problem exists for Float64 of course but for much smaller values).

1 Like

Thank you very much. I temporally use the following code instead.

f = Figure()
ax1 = Axis(f[1, 1], xgridvisible=false, ygridvisible=false, xticks=(0:0.2:1, string.((0:0.2:1).+60000)))
scatter!(ax1, 0:1e-3:1, ones(1001), markersize=1)
f