Qu

savefig

Builtin index · Plotting

savefig(path, [embed_fonts=])

Input: path, embed_fonts · Output: no output

What it is

Exports the current figure to path (string, a filesystem path); format is chosen by the file extension. .svg, .html/.htm (an SVG embedded in a minimal page), .tikz/.tex (LaTeX/TikZ source) and .pdf are implemented and share one draw-command list so they never visually disagree. .png is not implemented for a whole figure (it needs a real 2-D rasterizer) and raises a clear error saying so; save_image(path, img) does write a PNG of raster Value::Image content. embed_fonts= (bool) inlines the actual font bytes (only possible for the curated fontfamily(...) presets), subset to the glyphs the figure actually draws so a journal-theme figure costs tens of kilobytes rather than the whole font file; it defaults to on under a print-ready theme and off otherwise. A .pdf always embeds its faces, and subsets them the same way.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
savefig(path, [embed_fonts=])
path stringExports the current figure to path (string, a filesystem path).
embed_fonts bool, optionalembed_fonts= (bool) inlines the actual font bytes (only possible for the curated fontfamily(...) presets), subset to the glyphs the figure actually draws so a journal-theme figure costs tens of kilobytes rather than the whole font file.
no output.svg, .html/.htm (an SVG embedded in a minimal page), .tikz/.tex (LaTeX/TikZ source) and .pdf are implemented and share one draw-command list so they never visually disagree. A .pdf always embeds its faces, and subsets them the same way.

Examples

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

plot(t, noisy, color = "#b0b0b0")
plot(t, signal, color = "#0072BD")
xlabel("time [s]")
ylabel("amplitude")
savefig("my-first-figure.pdf")
output
· plot: figure 1 (1000 points)
· plot: figure 2 (1000 points)
· savefig my-first-figure.pdf
  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)
-1.5 -1.0 -0.5 0 0.5 1.0 1.5 2.0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 time [s] amplitude

from start-here

plot(v, v .^ 2)
xlabel("x")
ylabel("x^2")
grid on
savefig("squares.pdf")
output
· plot: figure 1 (2 points)
· savefig squares.pdf
  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)
100 150 200 250 300 350 400 10 11 12 13 14 15 16 17 18 19 20 x x^2

from fundamentals

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

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

from agent-guide