Text in colormesh cells

Hi everyone! In the lilaq function colormesh, is it possible to add text to each cell, such as the data itself? See an example below:

So far, I haven’t been able to figure it out. Thanks!

Hi @Thomas1 !

You can achieve this with lq.place analogously to the bar example Bar plot with numbers − Lilaq.

#let x = lq.arange(-2, 3)
#let y = lq.arange(-2, 3)
#let mesh = lq.mesh(x, y, (x, y) => x * y)

#lq.diagram(
  width: 4cm, height: 4cm,
  lq.colormesh(x, y, mesh),
  ..range(x.len())
    .map(col => range(y.len()).map(row => {
      let color = black
      let value = mesh.at(col).at(row)
      if value <= -2 {
        color = white
      }
      lq.place(
        x.at(col),
        y.at(row),
        text(color, str(value))
      )
    })
  ).join()
)

1 Like