# Makie artefacts around coloured region of surface?

**URL:** <https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [July 25, 2024, 1:21pm UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471 "2024-07-25T13:21:51Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [July 25, 2024, 1:21pm UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471/1 "2024-07-25T13:21:51Z")

</div>

I’m colouring certain regions of a surface, and at the transition between two colours there is a colour not present in the colour matrix given to the `color` attribute of the surface

I’m not exactly sure why this is happening, or if there is some setting I can change so this does not happen?

Any help very appreciated.

Compare surface (left) vs colour matrix (right):  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/0/c0b8196ab59a822fc67b9894e70522b41e8416f3.png)

Code to produce:

```julia
using GLMakie

x = 0:0.01:1
y = 0:0.01:1

function meshgrid(x,y)
    X = ones(length(y))*x'
    Y = ones(length(x))*y'
    return X,Y'
end

X,Y = meshgrid(x,y)
Z = [0.1*x for x in x, y in y]

C = zeros(length(x), length(y)) #colour matrix
C[:,5:10] .= 1
C[:,40:45] .= 2
C[:,70:75] .= 3
C[:,90:95] .= 4

f,ax,s=surface(X,Y,Z,color=C,lowclip=:blue,colorrange=(1,4),shading=NoShading)
ax,s=heatmap(f[1,2],C,lowclip=:blue,colorrange=(1,4))
f

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 25, 2024, 2:19pm UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471/2 "2024-07-25T14:19:26Z")

</div>

That’s because of interpolation.  
I’m not sure if that’s the correct interpolation behavior, but heatmap with `interpolate=true` looks the same.  
You can do:

```julia
f, ax, s = surface(X, Y, Z, color=C, lowclip=:blue, interpolate=false, colorrange=(1, 4), shading=NoShading)

```

But currently `interpolate` got lost on `Makie@0.21` due to the attribute validation refactor.  
Will try to add it back in the next release.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 25, 2024, 2:27pm UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471/3 "2024-07-25T14:27:42Z")

</div>

> <https://github.com/MakieOrg/Makie.jl/pull/4056>

---

<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:** [July 25, 2024, 2:28pm UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471/4 "2024-07-25T14:28:08Z")

</div>

Brilliant, thank you!

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [July 26, 2024, 8:46am UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471/5 "2024-07-26T08:46:20Z")

</div>

This looks like color interpolation at the boundary between two cells. This PR to Makie should make disabling that interpolation possible.

Unfortunately, `surface` is currently a continuously colored mesh, so there’s not an easy way to do this immediately.

---

<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:** [July 26, 2024, 11:50am UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471/6 "2024-07-26T11:50:27Z")

</div>

Setting `interpolate = false` did fix it, I think it was just undocumented for the `surface` plot?

I think I originally discounted interpolation being the cause because it did not look like correct interpolation to me. You can see here all three colours go to dark blue before an abrupt jump to the lowclip colour. It looks like the interpolation disregards the `lowclip` colour which is causing this odd effect:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/7/c7768a0bac950972d3ccf5d1b23ff5b0d1b3bd68.png) ![image](https://global.discourse-cdn.com/julialang/original/3X/d/d/ddfd11ee3380a0c7fa8f0d8eba408973805679c9.png) ![image](https://global.discourse-cdn.com/julialang/original/3X/a/e/ae4065b8ad8c84971cfd2fee1b1c3ee7c914e939.png)

edit: upon reflection, choosing how interpolate from a colour in the colourmap to the `lowclip` colour seems difficult, and probably not worth the time thinking about. I assume interpolation just goes linearly along the colourmap using the data, but interpolating to a colour not in the colourmap would require using a more general colour interpolation, which is much more difficult and would probably introduce its own problems. So I do now understand this interpolation behaviour.

---

<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:** [July 26, 2024, 12:29pm UTC](https://discourse.julialang.org/t/makie-artefacts-around-coloured-region-of-surface/117471/7 "2024-07-26T12:29:18Z")

</div>

Well the value-based interpolation would go smoothly from some value above clipping until the clipping point, and then jump to lowclip. Interpolation doesn’t happen in color space.
