# Different behaviour between CairoMakie and GLMakie

**URL:** <https://discourse.julialang.org/t/different-behaviour-between-cairomakie-and-glmakie/94405>\
**Category:** General Usage\
**Tags:** plotting, makie\
**Created:** [February 10, 2023, 10:24am UTC](https://discourse.julialang.org/t/different-behaviour-between-cairomakie-and-glmakie/94405 "2023-02-10T10:24:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maucejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maucejo/32/39090_2.png) [@Maucejo](https://discourse.julialang.org/u/Maucejo)\
**Post date:** [February 10, 2023, 10:24am UTC](https://discourse.julialang.org/t/different-behaviour-between-cairomakie-and-glmakie/94405/1 "2023-02-10T10:24:05Z")

</div>

Hi all,

I am confused since a couple of days, because GLMakie and CairoMakie have a different behavior. Here is the MWE:

```julia
using CairoMakie
# using GLMakie

x = range(0., 2π, 100)
z = sin.(x)

x = range(0., 2π, 100)
z = sin.(x)
zmin = minimum(z)

lower = [Point3f(x[i], 1, zmin) for i in eachindex(x)]
upper = [Point3f(x[i], 1., z[i]) for i in eachindex(x)]
edge_start = [Point3f(x[1], 1., zmin), Point3f(x[1], 1., z[1])]
edge_end = [Point3f(x[end], 1., zmin), Point3f(x[end], 1., z[end])]

fig = Figure()
ax = Axis3(fig[1,1])
band!(ax, lower, upper, color = (:blue, 0.1))
lines!(ax, upper, color = z, colormap = :viridis)
lines!(ax, edge_start, color = [z[1], z[1]], colormap = :viridis)
lines!(ax, edge_end, color = [z[end], z[end]], colormap = :viridis)

fig # for plotting CairoMakie figure in VSCode
# display(fig) # When using GLMakie

```

While this code works fine with `GLMakie`, it throws the following error when using `CairoMakie`: `Looking up a non-finite or NaN value in a colormap is undefined.`

After inspection, the problem comes from `lines!(ax, edge_start, color = [z[1], z[1]], colormap = :viridis)` and `lines!(ax, edge_end, color = [z[end], z[end]], colormap = :viridis)`, but I have to admit that I can’t explain why `GLMakie` and `CairoMakie` behave differently in this case.

Thanks for your help.

```julia
versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 20 × Intel(R) Xeon(R) W-2255 CPU @ 3.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, cascadelake)
  Threads: 1 on 20 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 1

```

```julia
(@v1.8) pkg> st
Status `~/.julia/environments/v1.8/Project.toml`
[13f3f980] CairoMakie v0.7.5
[e9467ef8] GLMakie v0.5.5

```

---

<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:** [February 10, 2023, 12:27pm UTC](https://discourse.julialang.org/t/different-behaviour-between-cairomakie-and-glmakie/94405/2 "2023-02-10T12:27:34Z")

</div>

They behave differently because the lookup is done by a shader on the GPU for GLMakie. The reason is that you’re passing a vector with twice the same value, so the automatic color range is computed as `(val, val)` so the range is `0` wide, which means that linear interpolation of the colormap fails. Pass the known min and max values manually as `colorrange = (min, max)` to avoid this.

---

<div class="post-metadata">

**Author:** ![Maucejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maucejo/32/39090_2.png) [@Maucejo](https://discourse.julialang.org/u/Maucejo)\
**Post date:** [February 10, 2023, 1:22pm UTC](https://discourse.julialang.org/t/different-behaviour-between-cairomakie-and-glmakie/94405/3 "2023-02-10T13:22:30Z")

</div>

Thanks @jules. I have just tried this code on my windows machine with `CairoMakie` and it works. On my windows machine, the version of `CairoMakie` is v0.10.2, while it is v0.7.5 on my Linux machine. I can’t access my Linux machine right now, but I will upgrade `CairoMakie` next week. I’ll keep you inform.
