Subpar Lilaq Colormesh and Colorbar Missalignment

Hello! I’m testing writing reports for my class but I’m having trouble adding a colorbar to my lilaq colormesh, instead being side by side it is one above the other. I solved the positioning by changing the columns spacing but I ran into another problem, the bar isn’t the same height as the colormesh. How can I solve it?

#subpar.grid(
  // (a) Histogram
  figure(
    lq.diagram(
      width: 7cm,
      height: 5.5cm,
      xlabel: [Joint angle (rad)],
      ylabel: [Count],
      lq.bar(bin-mids, hist-d.counts, width: bin-w, fill: c-navy),
    ),
    caption: [Marginal distribution of joint angles],
  ),
  <eda-hist>,

  // (b) Correlation heatmap  (z[y_idx][x_idx] = corr_d.values[row][col])
  figure(
    {
      // TODO: adjust colobar not side by side with heatmap
      let cm = lq.colormesh(
        idx20,
        idx20,
        corr-d.values,
        map: color.map.viridis,
      )
      lq.diagram(
        width: 6.5cm,
        height: 6.5cm,
        xlabel: [Joint index],
        ylabel: [Joint index],
        xaxis: (tick-distance: 5),
        yaxis: (tick-distance: 5),
        cm,
      )
      h(2mm)
      lq.colorbar(cm, thickness: 3mm)
    },
    caption: [Absolute Pearson correlation],
  ),
  <eda-heatmap>,

  columns: (1fr, 1.3fr),
  caption: [Exploratory data analysis: (a) marginal distribution of training joint angles and (b) pairwise absolute correlation heatmap (joint indices 0–19 defined in @tab-joints).],
  label: <fig-eda>,
)

Hi @gabrielluizep ,

Probably there is just not enough space but it is hard to check since your example is not directly compilable as is.

I recommend using a grid with lq.layout, see Plot grids − Lilaq to layout the diagram and the colorbar side-by-side. Since Lilaq 0.6.0, this is the way to go!

Oh, and you need to match the height of the colorbar to that of the diagram if you change it! Like so lq.colorbar(.., height: 6.5cm). Or even better

#figure({
  show: lq.set-diagram(width: 6.5cm, height: 6.5cm)
  show: lq.layout
  grid(
    columns: 2,
    column-gutter: 2mm,
    lq.diagram(
        xlabel: [Joint index],
        ylabel: [Joint index],
        xaxis: (tick-distance: 5),
        yaxis: (tick-distance: 5),
        cm,
    ),
    lq.colorbar(cm, thickness: 3mm)
  )
}

Thanks for the help @Mc-Zen. I’ve achieved my result by looking in the tutorial that you provided me!

An exemple of what I should have done

#import "@preview/lilaq:0.6.0" as lq

#let cm = lq.colormesh(
  (1, 2, 3),
  (1, 2, 3),
  ((0, 1, 2), (3, 4, 5), (6, 7, 8)),
  map: color.map.viridis,
)

#figure(
  {
    show: lq.layout
    grid(
      columns: 3,
      column-gutter: 1.5em,

      lq.diagram(
        width: 5.5cm,
        height: 5.5cm,
        lq.plot((1, 2, 3), (3, 2, 5)),
        lq.plot((1, 2, 3), (4, 4.5, 3)),
      ),

      lq.diagram(
        width: 5.5cm,
        height: 5.5cm,
        cm,
      ),

      lq.colorbar(width: .5cm, height: 5.5cm, cm),
    )
  },
  caption: [Example.],
)
2 Likes

Great!

You can mark the question as answered to help others finding the solution to similar problems.

Welcome to the forum!

1 Like