cetz-plot icon indicating copy to clipboard operation
cetz-plot copied to clipboard

y-axis in log mode cannot go below 1e-6

Open SolidTux opened this issue 1 year ago • 2 comments

When plotting in log mode, there is no way for the y-axis to go below 1e-6. Note that also the y-tick-step is necessary, as otherwise the compilation crashes due to too many ticks (is this a bug?)

Document

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

#set page(width: auto, height: auto, margin: 5mm)

#cetz.canvas(
  {
    plot.plot(
      size: (6, 3),
      y-mode: "log",
      y-format: "sci",
      y-tick-step: 1,
      y-min: 1e-7,
      {
        plot.add((
          (0, 1e-7),
          (1, 1e-6),
          (2, 1e-2),
        ),
          mark: "o"
        )
      }
    )
  }
)

2024-11-25 plot

SolidTux avatar Nov 25 '24 12:11 SolidTux

I assume this stems from the fact, that there is a floating point epsilon in cetz defined as exactly that value. One can get around this problem by rescaling the data and then scaling it back in the tick formatter. For example like this

#cetz.canvas(
  {
    plot.plot(
      size: (6, 3),
      y-mode: "log",
      y-format: y => plot.formats.sci(y / 1e2),
      y-tick-step: 1,
      y-min: 1e-5,
      {
        plot.add((
          (0, 1e-7),
          (1, 1e-6),
          (2, 1e-2),
        ).map(
          ((x, y)) => (x, y * 1e2)
        ),
          mark: "o"
        )
      }
    )
  }
)

2024-11-25 plot

SolidTux avatar Nov 25 '24 13:11 SolidTux

This is possibly related to #64

jamesrswift avatar Dec 01 '24 09:12 jamesrswift