# GLMakie vs Plots, not enogh precision for axis limits

**URL:** <https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249>\
**Category:** General Usage\
**Tags:** plots, makie, glmakie\
**Created:** [March 6, 2024, 4:29pm UTC](https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249 "2024-03-06T16:29:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 6, 2024, 4:29pm UTC](https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249/1 "2024-03-06T16:29:51Z")

</div>

I have ugly data with an ugly code, but I just used scatter in both places.

Plots gives this:  
 ![Screenshot from 2024-03-06 17-26-08](https://global.discourse-cdn.com/julialang/original/3X/b/0/b05532be43e973e13d3426f40c8e62527d94de37.png)

And, as you can see, the oscillations are in the double order.

GLMakie gives this:

![Screenshot from 2024-03-06 17-24-54](https://global.discourse-cdn.com/julialang/original/3X/2/d/2d83beed4708acc596dbf8e3d8ab70183e52101e.png)

If you zoom manually all the data behaves in the same way, however I can’t manually set it each time. Is there a way to say to GLMakie to not give up in setting axis limits?

P.S: I included a simple code:

```julia
using GLMakie

x = [1, 2]
y = Float64[1.00000001, 1.00000002]
f = Figure()
ax = Axis(f[1, 1])
scatter!(x, y)
display(f)

```

And GLMakie just gives up:  
 ![Screenshot from 2024-03-06 17-50-28](https://global.discourse-cdn.com/julialang/original/3X/9/0/90ee8dd09c8a003106d22274cb0f0c82c2edd286.png)

Found this:

> <https://github.com/MakieOrg/Makie.jl/issues/1196>
>
> I posted an \[issue\](https://discourse.julialang.org/t/loss-of-precision-when-plo…tting-large-floats-in-makie/65802) to the Julia discourse, and the helpful replies there seem to suggest that this may be a bug in (or downstream from?) Makie, so I figured I'd file an issue here also since I couldn't find a duplicate in the issue tracker.
> 
> For completeness, I'll repeat my issue here: I'm doing something which I've reduced to:
> 
> \`\`\`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)
> \`\`\` 
> 
> This produces:
> 
> !\[image\](https://user-images.githubusercontent.com/25851939/128203704-799262f2-d4f0-4116-9b8f-d1117e035e39.png)
> 
> Whereas I'd expected a straight line. As \[\`johnmyleswhite\`\](https://discourse.julialang.org/t/loss-of-precision-when-plotting-large-floats-in-makie/65802/2) points out in the discourse, the loss of precision is not in the data itself, but seems to happen somewhere along the plotting machinery.
> 
> I'm running Makie 0.15.0 with Julia 0.16.2 on Manjaro Linux.
> 
> Thank you for the library, I've found it very enjoyable to use.

---

<div class="post-metadata">

**Author:** ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)\
**Post date:** [March 6, 2024, 5:17pm UTC](https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249/2 "2024-03-06T17:17:02Z")

</div>

You could try `tightlimits!(ax)` to force makie to zoom in around the points.

Regarding your example, I think the issue is that Makie converts everything to Float32 and so you lose the precision

```julia
Float32(1.00000001)
1.0f0

```

You can manually get around it by doing something like this:

```julia
x = [1, 2]
y = [1.00000001, 1.00000002]
yscaled = (y .- 1) .* 10^8

f = Figure()
ax = Axis(f[1, 1])
scatter!(x, yscaled)
ax.ytickformat=values->["$(round(value/10^8 + 1,digits=8))" for value in values]
display(f)

```

which gives this:

![image](https://global.discourse-cdn.com/julialang/original/3X/7/8/78f7a43793184f5d57ede80a41450be6fd7d85f1.png)

---

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 6, 2024, 9:30pm UTC](https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249/3 "2024-03-06T21:30:58Z")

</div>

I can’t do that in my case. It was just a simple example. I need to rewrite everything in Plots, as nothing in Makie supports Float64 as ticks

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 7, 2024, 9:18am UTC](https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249/4 "2024-03-07T09:18:54Z")

</div>

My suggestion would be to make some data transformation before plotting. For example, subtract the mean value and then divide by the new mean value, to get a proper scaling for the comparison.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 7, 2024, 9:22am UTC](https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249/5 "2024-03-07T09:22:31Z")

</div>

While I get that it’s annoying not to have the full Float64 range available right now for plotting in Makie, I also think that often plots that go to the tiny or huge float values are pretty hard to read. So for visualizations that are not one-offs where you quickly want to see some data, the scaling step is usually bearable. There is some work ongoing in Makie to improve the situation, but I don’t know when it will come to fruition.

---

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 7, 2024, 9:48am UTC](https://discourse.julialang.org/t/glmakie-vs-plots-not-enogh-precision-for-axis-limits/111249/6 "2024-03-07T09:48:13Z")

</div>

Oh no, they are quite easy to read.

I found a solution here with the pythonplot package:

> [@Julia in Python, Float64 plots needed](https://discourse.julialang.org/t/julia-in-python-float64-plots-needed/111279/5):
>
> Do you know how to set the default saving directory from pythonplot? in “pythonized julia” I would use: const dir\_save\_image = "/home/matteobacci/Desktop/Latex/Ising/Ising\_Images/modulo\_05/" pyplot.rcParams["savefig.directory"] = os.chdir(os.path.dirname(dir\_save\_image)) But os.stuff isn’t defined here
