Hello!
I got the following code in Typst:
Code to Generate Plot
#import "@preview/cetz:0.3.1"
#import "@preview/cetz-plot:0.1.0": *
#cetz.canvas({
import cetz.draw: *
let style = (stroke: black, fill: rgb(0, 0, 200, 75))
let f1(x) = calc.sin(x)
let nonum(eq) = math.equation(block: true, numbering: none, eq)
let fn = (
(blue, nonum($ "Cubic Spline" $), q => float(q >= 0) * float(q <= 1) * (1 - ((3/2) * q * q) + ((3/4) * q*q*q)) + float(q > 1) * float(q <= 2) * (1/4 * (2 - q) * (2 - q) * (2 - q))),
(orange, nonum($ "Wendland Quintic" $), q => float(q >= 0) * float(q <= 2) * ((1-q/2)*(1-q/2)*(1-q/2)*(1-q/2)*(2*q + 1))),
)
let fn_der = (
(blue, nonum($ "Cubic Spline - dWdq" $), q => float(q >= 0) * float(q <= 1) * (-3*q + (9/4)*q*q) + float(q > 1) * float(q <= 2) * (-(3/4)*(q - 2)*(q - 2))),
(orange, nonum($ "Wendland Quintic - dWdq" $), q => float(q >= 0) * float(q <= 2) * ((5/8)*q*(q - 2)*(q - 2)*(q - 2))),
)
// Set-up a thin axis style
set-style(axes: (stroke: .5pt, tick: (stroke: .5pt), ),
legend: (stroke: none, orientation: ttb, item: (spacing: .3), scale: 80%))
// Draw x-line at 0, in a terrible way
line((0, 4.4375 ), (12, 4.4375), mark: (end: none), name: "long_line")
// Define W(q) box
content(
(-3.35, 7),
(-1.25, 5),
box(
par(justify: false)[#nonum($ W(q) $)],
stroke: 1pt,
width: 100%,
height: 75%,
inset: 1em
)
)
// define dW(q)/dq box
content(
(-3.35, 1),
(-1.25, 3),
box(
par(justify: false)[#nonum($ (dif W(q)) / (dif q) $)],
stroke: 1pt,
width: 100%,
height: 75%,
inset: 1em
)
)
// Perform plot
plot.plot(size: (12, 8),
x-label: "q",
y-label: none,
x-tick-step: 1,
// x-format: plot.formats.multiple-of,
y-tick-step: 0.25, y-min: -1.25, y-max: 1,
legend: "inner-north",
{
let domain = (0, 3)
for ((paint, title, f)) in fn {
plot.add(f, style: (stroke: (paint: paint)), domain: domain, label: title)
}
for ((paint, title, f)) in fn_der {
plot.add(f, style: (stroke: (paint: paint, dash: "dashed")), domain: domain, label: title)
}
})
})
This gives me the following result:
I wish to remake the following graph:
What I specifically want to do is at a minimum:
- Remove the square axes and use the similar visualisation
- I want to make xline much easier, I had to “guess” coordinates, I do not want to do so
- Likewise with the boxes to write W(q), dW(q)/dq etc. I had to guess coordinates, instead of being able to put it relatively to y-axis
Hope you can help me level up my skills and achieve my goal in Typst!
Kind regards