plothexport("svg", X = -3, 3, sin(X))sin(x) on [-3, 3]
gp has no notion of a “current figure” the way R or matplotlib do. A plot reaches the document because you asked gp for it: plothexport("svg", ...) returns the SVG document itself, and the engine turns any cell whose output is an SVG into a figure.
print(plothexport(...)) works too; both the quoted value gp prints for a string and the raw printed form are recognised.
Give the cell a label starting with fig- and the figure becomes cross-referenceable, as in Figure 1.
plothexport takes a vector of expressions, and the flag 1 joins the points:
fig-width sets the CSS width of an inline SVG; gp’s own width and height go to plothsizes-aware functions, or as the last arguments of plothexport.
For HTML the SVG goes straight into the page, so it stays sharp at any zoom and there is no file to keep track of. For every other format the SVG is written to the document’s _files directory and referenced as an image, which Quarto copies and cleans up as usual.
The rule is simple: a cell whose output is an SVG document becomes a figure. Every gp function that returns SVG therefore works, and there are three of them:
| Function | Draws |
|---|---|
plothexport("svg", X = a, b, expr) |
a function of one variable |
plothrawexport("svg", xs, ys) |
a list of points you computed yourself |
plotexport("svg", w) |
a drawing built with plotinit / plotrecth |
plothrawexport is how you plot data rather than a formula:
And plotexport draws a rectangle you composed yourself:
ploth, plothraw and plotdraw draw to a screen device, so there is nothing for the engine to capture during a render — use their …export counterparts above.
psploth and psplothraw write a PostScript file (pari.ps by default) rather than returning a string. No browser renders PostScript, so the engine does not pick these up. If you need PostScript, call them, convert the file yourself, and reference the result with ordinary markdown.