Qu

figure

Builtin index · Plotting

figure()

Input: no input · Output: no output

What it is

Clears/resets the whole figure (all panels), starting a fresh one. Takes no arguments. Must be called with parentheses — bare figure (no parens) is not a recognized command verb.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
figure()no inputno outputClears/resets the whole figure (all panels), starting a fresh one. Takes no arguments. Must be called with parentheses — bare figure (no parens) is not a recognized command verb.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

figure()
plot([0, 1], [0, 1])
show plot
plot([0, 1], [1, 0])
show plot   # a second, separate figure -- NOT the first plot plus this one

output
· plot: figure 3 (2 points)
· show plot
· plot: figure 5 (2 points)
· show plot
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

from agent-guide

tri = triangle(5, 500, 200)
plot(tri, label = "triangle")
figure()
saw = sawtooth(5, 500, 200)
plot(saw, label = "sawtooth")
figure()
s = sweep(10, 100, 500, 400)
plot(s, label = "sweep")
output
· plot: figure 65 (200 points)
· plot: figure 66 (200 points)
· plot: figure 67 (400 points)
-1.0 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1.0 0 50 100 150 200 250 300 350 400

from plotting

tmp_svg = tmp_file() + ".svg"
figure()
polygon([0.0, 1.0, 1.0], [0.0, 0.0, 1.0], fill = "#ff0000")
savefig(tmp_svg)
print(contains(read_all_text(tmp_svg), "opacity=\"0.18\""))   # true

output
· savefig <tmp>.svg
  note: this figure uses screen styling and may not hold up in print -- call theme("publication") before saving for a paper (said once per session)
  note: fonts render using whatever is installed on the viewer's machine (none are embedded) -- pass embed_fonts=true (fontfamily preset only) or export .tikz for guaranteed appearance
true
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

from agent-guide

figure()
polygon([0.0, 1.0, 1.0], [0.0, 0.0, 1.0], fill = "#00ff00", alpha = 1.0)
figure_size(200, 150, unit = "mm")
polygon([2.0, 3.0, 3.0], [0.0, 0.0, 1.0], fill = "#0000ff", alpha = 1.0)
savefig(tmp_svg)
print(regex_count(read_all_text(tmp_svg), "<polygon"))   # 2, not 1

output
· savefig <tmp>.svg
  note: fonts render using whatever is installed on the viewer's machine (none are embedded) -- pass embed_fonts=true (fontfamily preset only) or export .tikz for guaranteed appearance
2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0 0.5 1.0 1.5 2.0 2.5 3.0

from agent-guide

How it works

Starts a genuinely new, separate figure -- unlike the bare clear/clear figure *command* (exec_clear_command's [] | ["figure"] arm), which discards the current figure's content outright, figure() finalizes it into self.figure_history first (if it actually has content -- two back-to-back figure() calls with nothing plotted between them shouldn't record an empty figure) so it can still be recovered later for reports. See figure_history's field doc comment.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.