How to draw a simple parabola function in CeTZ?

I’m trying to figure our how to draw a simple function (say y=x^2) in cetz.

Ideally I’d like to be able to draw Desmos like functions directly into my documents.

I can draw a trig graph but will get error messages every time I try to convert to something else e.g 1/x, x^2 etc.

Here’s the code of the trig graph that I’ve got working so far, but how can I transform the sine graph to a parabola?

#import@preview/cetz:0.3.2”
#import@preview/cetz-plot:0.1.1”
cetz.canvas(
{
import cetz.draw: *
import cetz-plot: *

plot.plot(size: (5,5), x-tick-step: none, y-tick-step: none,
plot.add(
domain: (0,2*calc.pi),
(calc.sin)
)
)
}
)

1 Like

Because the calc.sin function only uses one parameter you can use your syntax.
The calc.pow function needs a base and an exponent, so you can’t just write (calc.pow) but need to assign the x values explicitly:

#import "@preview/cetz:0.3.2"
#import "@preview/cetz-plot:0.1.1"
#cetz.canvas(
{
import cetz.draw: *
import cetz-plot: *

plot.plot(
    size: (5,5),
    x-tick-step: none,
    y-tick-step: none,
    
    plot.add(
        domain: (0,5),
        x => calc.pow(x, 2)
    )
)
}
)

If you need any further help styling your plot “Desmons like” just let me know or post a screenshot of how your final plot should look.

1 Like