How would I limit ticks to integer values in lilaq?

I would like to have the smallest step of my diagrams xaxis be 1. Meaning that if the xaxis goes from 0 to 1, lilaq does not insert ticks at 0.2, 0.4, 0.6, …

What I currently have:
X-axis with ticks at decimal values

What I want to have:
Desired x-axis with only ticks at integer values

I tried setting subticks to none.
tick-distance: 1, which is what I did for the desired image, but if the values get larger, a tick for every integer value is too much.

Any ideas on how this can be achieved?

Hi there @Gaweringo,

Yes it is possible. For the x axis only you can try:

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

#lq.diagram(
  xaxis: (
    lim: (0,1), 
    tick-distance: 1, 
    subticks: 0
  ),
) 

1 Like

Yeah, but it becomes a problem, if the limit gets bigger:

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

#lq.diagram(
  xaxis: (
    lim: (0,150), 
    tick-distance: 1, 
    subticks: 0
  ),
)

Diagram with tick distance 1 and limit 150

I have now made the tick-distance dependent on the maximum x value of my data:

#let xtick-distance = calc.max(1, calc.round(calc.max(..x)/5))

And lilaq seems to still automatically make the ticks be nice values (which is exactly what I want in this case, but is not what I expected), as for the data in the image below, the max value is 144, thus xtick-distance would be 29, and not 30:

tick-distance for xaxis based on max x value

Hi @Gaweringo ,

You can either let Lilaq decide on the tick-distance or pass it manually. There is no in-between.

What you could try is to compute the range of the axis (max - min) and only set the tick-distance to 1 for small ranges but leave it at auto if the range is sufficiently large.

2 Likes