I’m looking for a Makie equivalent to the matplotlib pcolormesh
. I attempted to do this with the mesh
plotting function in CairoMakie.
I’m testing my code by trying to reproduce this plot from the pcolormesh
documentation.
Here is my attempt:
using GeometryBasics, CairoMakie
x = hcat([range(-0.5, 10, length=10) for i in 1:6]...)'
y = hcat([collect(range(4.5, 11, length=6)) for i in 1:10]...)
X2d = x.+0.2.*y
Y2d = y +0.3.*x
Z2d = hcat([[0.7003673 , 0.74275081, 0.70928001, 0.56674552, 0.97778533,
0.70633485, 0.24791576, 0.15788335, 0.69769852, 0.71995667],
[0.25774443, 0.34154678, 0.96876117, 0.6945071 , 0.46638326,
0.7028127 , 0.51178587, 0.92874137, 0.7397693 , 0.62243903],
[0.65154547, 0.39680761, 0.54323939, 0.79989953, 0.72154473,
0.29536398, 0.16094588, 0.20612551, 0.13432539, 0.48060502],
[0.34252181, 0.36296929, 0.97291764, 0.11094361, 0.38826409,
0.78306588, 0.97289726, 0.48320961, 0.33642111, 0.56741904],
[0.04794151, 0.38893703, 0.90630365, 0.16101821, 0.74362113,
0.63297416, 0.32418002, 0.92237653, 0.23722644, 0.82394557],
[0.75060714, 0.11378445, 0.84536125, 0.92393213, 0.22083679,
0.93305388, 0.48899874, 0.47471864, 0.08916747, 0.22994818]]...)'
data = vec([(Float32(xv), Float32(yv)) for (xv,yv) in zip(vec(X2d), vec(Y2d))])
heights = [i for i in vec(Z2d)]
faces = decompose(QuadFace{GLIndex}, Tesselation(Rect(0, 0, 1, 1), size(X2d)))
msh = GeometryBasics.Mesh(GeometryBasics.Point2f.(data),faces)
fig = CairoMakie.Figure();
ax = Axis(fig[1,1], aspect=1)
CairoMakie.mesh!(ax, msh, color=heights)
display(fig)
This code produces an image that looks like this:
Which is very close to the correct answer except that it seems like the the mesh interpolates the vertex colors. Is there a way to stop that interpolation and to just have a flat color shading on each QuadFace
?