How do share an axis between diagrams

I am trying to make a Figure with a “discontinuous” axis. Something like the following example (but vertical instead of horizontal):

I guess this is too niche, and there is no built-in way to do this, right?

So I am trying to do it with 2 diagrams on top of each other, but I am having some issues with a couple of things.

I can get something that starts looking in the correct direction:

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

#lq.diagram(
  width: 8.9cm,
  height: 2cm,
  legend: (position: (100% + .5em, 0%)),
  xaxis: (position: top, format-ticks: none),
  lq.plot(
    (0, 100, 200, 300),
    (320, 310, 300, 290),
    label: [Observed Input~~~],
  ),
  lq.fill-between(
    (0, 300),
    (310, 310),
    y2: (295, 295),
    label: [Estimated Input],
    z-index: 1,
  ),
)

#lq.diagram(
  width: 8.9cm,
  height: 2cm,
  xaxis: (position: bottom),
  xlabel: [MLU wait gate [8 ns]],
  legend: (position: (100% + .5em, 0%)),
  lq.plot(
    (0, 100, 200, 300),
    (180, 160, 170, 130),
    label: [Observed Output],
  ),
  lq.fill-between(
    (0, 300),
    (175, 175),
    y2: (150, 150),
    label: [Predicted Output],
    z-index: 1,
  ),
)

which gives me

Issues I am having:

  • I don’t know how to add these / / (or similar) between the gaps at the edges of the axis to give the idea of “discontinuous”.
  • I don’t know how to add a ylabel that is shared between both. If I try adding e.g. ylabel: [Counter rate [Hz]] to either of them, I can’t get it to not wrap around (and it shifts the individual diagram to the side, so they are not aligned any more).

Hi @Katty ,

I have already been thinking about this but I couldn’t come up with a nice solution that could be made built in.

You can draw these little separation lines with std.line and lq.place. The lilaq place function can also draw onto the axes as demonstrated in its docs.

As for the y label, you could wrap the label in a box that is long enough to make it fit and then move it with std.move. It’s not quite optimal but it should work. Edit: you can right-align both diagrams so that the alignment issue goes away.

Another way would be to use just one diagram and write a special axis scale that treats the omitted region in a special way. But that’s not entirely trivial to achieve. You would also need dedicated tick locators for that.

1 Like