Skip to content

Feature request: Add samples parameter to customize plot sampling rate. #7

Description

@FramHerel

Is your feature request related to a problem? Please describe.

Currently, there is no option to customize the sampling resolution (number of samples) when generating function plots. When plotting rapidly oscillating functions, high-frequency curves, or functions across a wide domain, the default sampling resolution may lead to visible aliasing or jagged lines due to insufficient points.

Describe the solution you'd like

Expose the underlying cetz-plot parameter samples in simple-plot functions.

This parameter should accept an integer (e.g., samples: 200) to define how many points are evaluated across the plot range.

Example Usage

#import "@preview/simple-plot:1.0.0":plot
#import "@preview/cetz-plot:0.1.4"
#import "@preview/cetz:0.5.2"
#plot(
  xmin:-5,
  xmax:5,
  (fn:x => calc.sin(x * 10)),
)

#cetz.canvas({
  import cetz.draw: *
  import cetz-plot: *
  plot.plot(
    size: (6, 6),
    axis-style: "school-book",
    x-min:-5,
    x-max:5,
    y-min:-5,
    y-max:5,
    {
      plot.add(
      domain: (-5, 5),
      samples: 2000,
      style: (stroke: blue + 1.2pt),
      x => calc.sin(x * 10),
      )
    },)
})
Image

Additional Context

Allowing direct control over samples improves flexibility for users who need higher resolution for dense plots, or lower resolution to speed up document rendering when precision is non-critical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions