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):
Code to produce:
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
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:
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.
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:
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.
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.