Cetz Plot: How can I reduce grid padding?

Is it possible to make it so that the arrows from the axes go just a little bit beyond the limits? Like the red x-axis that I drew.

#import "@preview/cetz:0.3.1": canvas, draw
#import "@preview/cetz-plot:0.1.0": plot


#let f(x) = {(x)}

#set text(size: 5pt)


#canvas(length: 0.7cm, {
  import draw: *
  
  set-style(
    axes: ( stroke: .5pt, inset: 0pt,  tick: (length: 0,stroke: .5pt, label: (offset: 2pt)), grid: (stroke: gray + .3pt, padding: 0pt)), legend: (padding: 0pt,),
  )
  plot.plot(
    size: (4, 4),
    plot-style: (stroke: black + 0.6pt,),
    axis-style: "school-book",
    legend-style: (length: 0),
    y-tick-step: 1,
    x-tick-step: 1,
    y-equal: "x",
    x-grid: true,
    y-grid: true,
    {
      plot.add(f, domain: (-4,4),)
    }
  )
}) ```

There are some style options in the axes dictionary for that, which you can adjust:

  • padding – How much the axis lines should reach outside the plot area on both sides. You can see this in your image, where the line goes outside the grid on the left and bottom. By default, it is set to 0.1cm.

  • overshoot – Basically the same as padding, but only for the side with the arrow head (i.e. on the right or top). This value is added to the padding value, and defaults to 0.5cm.

  • mark – Some style options to change the appearance of the arrow head. For example, you can make it smaller by changing the length or width. You can find more about mark styling in the documentation of CeTZ.

In total, that might then look like this:

#canvas({
  import draw: *
  
  set-style(
    axes: (
      padding: 0pt,
      overshoot: 6pt,
      mark: (length: 3pt)
      ...
    ),
    ...
  )

  plot.plot(...)
})

image

1 Like