# Loss of precision when plotting large floats in Makie

**URL:** <https://discourse.julialang.org/t/loss-of-precision-when-plotting-large-floats-in-makie/65802>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [August 4, 2021, 11:51am UTC](https://discourse.julialang.org/t/loss-of-precision-when-plotting-large-floats-in-makie/65802 "2021-08-04T11:51:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaltheSR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malthesr/32/27827_2.png) [@MaltheSR](https://discourse.julialang.org/u/MaltheSR)\
**Post date:** [August 4, 2021, 11:51am UTC](https://discourse.julialang.org/t/loss-of-precision-when-plotting-large-floats-in-makie/65802/1 "2021-08-04T11:51:13Z")

</div>

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:

```julia
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:

 ![example](https://global.discourse-cdn.com/julialang/original/3X/2/d/2da94bf25d2b049b669b07581190f161aa1d7207.png)

I would’ve expected a straight line of points, which is also what I see if I don’t add `1e7` to the `x`s. I’m sadly not familiar enough with Julia/Makie to be sure what’s going on here.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [August 4, 2021, 1:02pm UTC](https://discourse.julialang.org/t/loss-of-precision-when-plotting-large-floats-in-makie/65802/2 "2021-08-04T13:02:41Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 4, 2021, 1:11pm UTC](https://discourse.julialang.org/t/loss-of-precision-when-plotting-large-floats-in-makie/65802/3 "2021-08-04T13:11:59Z")

</div>

All numerical data in Makie is internally translated to Float32 before being plotted. For scatter plots this happens [here](https://github.com/JuliaPlots/Makie.jl/blob/84d552d6470fd5480baff0d89d932687e8b1cc09/src/conversions.jl#L156) 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.

---

<div class="post-metadata">

**Author:** ![MaltheSR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malthesr/32/27827_2.png) [@MaltheSR](https://discourse.julialang.org/u/MaltheSR)\
**Post date:** [August 4, 2021, 3:05pm UTC](https://discourse.julialang.org/t/loss-of-precision-when-plotting-large-floats-in-makie/65802/4 "2021-08-04T15:05:53Z")

</div>

Thank you both for the replies. I’ve filed an [issue](https://github.com/JuliaPlots/Makie.jl/issues/1196) in the Makie repository.
