The plots draw what a persistence computation returns: barcodes, persistence diagrams, persistence images and landscapes, images, complexes at a scale, cycles, cocycles and circular coordinates, in 2-D and in 3-D. They are part of the library, in the package org.appliedtopology.tda4j.plot, and need no other dependency: plots are SVG, or a page with a small built-in 3-D viewer, and they show up in your browser while you work in a REPL. The API is young and may still change between releases.

The sections up to What there is are all that most readers need. Everything under Customizing a plot is reference: look up the element you want to change.

In a REPL: view()

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = Array.tabulate(40)(i => Array(math.cos(i * 0.157), math.sin(i * 0.157)))
val diagram = Persistence(points, maxDimension = 1)

Plot.barcode(diagram).view()
Plot.diagram(diagram).view()

The first view() starts a small web server on your machine (http://127.0.0.1:8337/) and opens it in your browser: one tab that lists every plot you have viewed, newest first, and shows each new one as it arrives. Nothing to install, no windows to manage, and the REPL exits as usual. On a remote machine or in a container the address is printed instead; forward the port (ssh -L 8337:localhost:8337 host) and open it locally. Set TDA4J_PLOT_BROWSER=none (or the system property tda4j.plot.browser=none) to never open a browser, and the system property tda4j.plot.port (or TDA4J_PLOT_PORT) for another port.

The server answers only programs on your own machine. Where the page has to be read from elsewhere and the port cannot be forwarded (a container that publishes the port to its host), set TDA4J_PLOT_HOST (or the system property tda4j.plot.host) to the address to listen on; 0.0.0.0 is every address the machine has. The page has no password, so whoever reaches the port sees the plots.

A program that runs your code for you and has its own place for plots (a notebook, a page that hosts a REPL) takes them with Plot.viewWith: every view() inside its block goes to the function it was given, and the viewer does not start.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val square = Array(Array(0.0, 0.0), Array(1.0, 0.0), Array(1.0, 1.0), Array(0.0, 1.0))
val pages = scala.collection.mutable.ArrayBuffer.empty[String]

Plot.viewWith(plot => pages += plot.html()) {
  Plot.barcode(Persistence(square)).view()      // goes to `pages`, not to a browser tab
}

Into files: save

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = Array.tabulate(40)(i => Array(math.cos(i * 0.157), math.sin(i * 0.157)))
val diagram = Persistence(points, maxDimension = 1)

Plot.barcode(diagram).save("barcode.svg")            // plain light colors, no background
Plot.diagram(diagram).save("diagram.svg", Some(Theme.Dark))   // light ink, for a dark page
Plot.diagram(diagram).save("diagram.html")           // follows the reader's light or dark setting
Plot.side(Plot.barcode(diagram), Plot.diagram(diagram)).save("both.svg")

figure.svg() is the SVG as a string: a notebook cell that displays HTML, or any web page, shows it as it is.

A saved .svg has no background, so the figure takes the color of the paper, slide or page it goes onto; the cream behind a figure in the viewer, in figure.svg() and in an .html page is for a page of its own. A figure in the dark theme is light ink on nothing: put it on a dark page. Where a file must carry its own background (an image that has to be opaque, or a dark figure opened on its own), save figure.withOpaqueBackground(), or Palette.print + Style.print for a white one, as for a paper (see For a paper).

PNG and PDF

save writes SVG and HTML; a PNG or a PDF is one command on the saved .svg, with a tool that is already on most machines. The SVG is 96 pixels to the inch, so a scale of 2 is 192 dpi and 3.125 is 300 dpi.

# cairosvg (pip install cairosvg): PNG at 300 dpi, and a PDF that has the fonts it used inside
cairosvg diagram.svg -o diagram.png --scale 3.125
cairosvg diagram.svg -o diagram.pdf

# Chromium or Chrome: PNG at twice the size (the window is the figure's width and height), PDF on a page
chromium --headless --hide-scrollbars --force-device-scale-factor=2 --window-size=560,520 \
  --screenshot=diagram.png file:///path/to/diagram.svg
chromium --headless --no-pdf-header-footer --print-to-pdf=diagram.pdf file:///path/to/diagram.svg

# Inkscape 1.x: PNG, and a PDF with the text turned into outlines, for a publisher who wants no fonts
inkscape diagram.svg --export-type=png --export-dpi=300 --export-filename=diagram.png
inkscape diagram.svg --export-type=pdf --export-text-to-path --export-filename=diagram.pdf

# librsvg
rsvg-convert -f png -z 3.125 diagram.svg -o diagram.png
rsvg-convert -f pdf diagram.svg -o diagram.pdf

The figure names its fonts in a list, system-ui, ... by default and Helvetica, Arial, 'Liberation Sans', sans-serif in the print look (Style(font = ...) sets another), and a converter takes the first one it has installed: the letters of a PNG are those of that machine. For a figure that must look the same wherever it is opened, use a PDF, which holds the font, or Inkscape's outlines. Chromium's command line puts the figure in the corner of a letter-size page. A page that follows the reader's dark setting (.html) is not what a converter should be given: save the .svg in the theme you want (save("d.svg", Some(Theme.Dark))).

From MATLAB, Java and the command line

A result of the MATLAB interface draws itself: each plot... method returns a figure, to view() or save as above. Here, the loop of a noisy circle and its cycle, drawn over the complex at the scale where the loop is born:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)
import d.given
val loop = d.dim(1).longest.get

Plot.barcode(d).view()
Plot.cycle(points, loop.representative).over(Plot.complex(points, loop.birth)).save("loop.svg")
import org.appliedtopology.tda4j.matlab.*;

points = readmatrix('_docs/tutorials/data/noisy-circle.csv');
result = TDA4j.computeFromPoints(points, {'maxDimension', '1'});

result.plotBarcode().view();
loop = result.mostPersistentBar(1);          % the index of the loop's bar (counting from 0)
result.plotRepresentative(loop, result.birth(loop)).save('loop.svg');   % its 18 edges over the complex

result.save('circle.json');                  % everything, to plot again later
result = TDA4j.loadResult('circle.json');
import numpy as np
import tda4j

points = np.loadtxt("_docs/tutorials/data/noisy-circle.csv", delimiter=",")
result = tda4j.persistence(points, max_dimension=1)

result.plot_barcode().view()
loop = result.most_persistent_bar(1)       # the row of the loop's bar in result.bars (counting from 0)
result.plot_representative(loop, at=result.bars[loop, 1]).save("loop.svg")   # its 18 edges over the complex

result.save("circle.json")                 # everything, to plot again later
result = tda4j.load_result("circle.json")

In MATLAB, call the methods with dot syntax (fig.view(), fig.save('loop.svg')): save and view are also MATLAB functions. MATLAB itself is not run by the test suite; the same calls are made from Scala. In Python the methods are plot_barcode(), plot_diagram(), ... on the result, and the figure has svg(), html(), save(path) and view(); a notebook shows a figure by itself. The tweaks that take plain arguments are methods of a Python figure too, in snake_case (with_title("..."), with_x_scale("sqrt"), with_size(800, 600)), and tda4j.set_plot_defaults("palette=print") changes the look of all later plots, with the settings of the MATLAB setPlotDefaults.

method draws
plotBarcode(), plotBarcode(longest), plotDiagram() the reported bars; the subtitle says how many the threshold hid
plotRepresentative(i) bar i's cycle over the points, its cubical chain over a 2-D image, or its cocycle restricted to the complex at the bar's birth: the edges that close the loop
plotRepresentative(i, at) a cycle over the complex at scale at, or a cocycle restricted to the complex at at (Inf draws the whole cocycle)
plotInput(), plotComplex(at) the points or the image; the complex the result was computed from at at (a witness complex on its landmarks)
plotLandscape(dimension), plotPersistenceImage(dimension) the vectorizations, of every bar (as landscape and persistenceImage compute them)
plotInput3D(), plotComplex3D(at), plotRepresentative3D(i) the same in 3-D (cycles only)
mostPersistentBar(dimension) not a plot: the index of the most persistent reported bar of that dimension
circularCoordinates(...).plot(), toroidalCoordinates(...).plot() circular and toroidal coordinates

A result computed from a distance matrix or a relation has no coordinates: it draws its barcode, diagram, landscapes and persistence images, and says so for the rest. The command line draws the same figures with --plot:

java -jar tda4j-VERSION-assembly.jar --max-dimension 1 --save-result circle.json noisy-circle.csv
java -jar tda4j-assembly.jar --plot diagram --output diagram.svg circle.json
java -jar tda4j-assembly.jar --plot representative circle.json
java -jar tda4j-assembly.jar --plot barcode,diagram --layout 1x2 --tagged circle.json

The first line computes and prints the bars, and saves the whole result; the others plot it without computing again. --plot representative draws the most persistent bar of --dimension (default 1), or --bar N (its line number in the listing, counting from 0); --at gives the scale. A comma list of kinds is one board, in a row or on --layout. Without --output the plot opens in the browser. See the command-line page.

Saved results

result.save(path) and --save-result write a JSON file that TDA4j.loadResult(path) and the command line read back, from MATLAB, Java or Scala: every bar, which bars the threshold reported, their representatives, the points or image, and how the result was computed (options, field, the version of tda4j). It is plain JSON, so other languages read it too: dimensions, births, deaths hold every bar, reported the indices of the reported ones, and representatives their cells and coefficients. Infinite and missing values are the strings "Infinity", "-Infinity" and "NaN":

import json
r = json.load(open("circle.json"))
deaths = [float(d) for d in r["deaths"]]    # float() reads numbers and "Infinity" alike

The boundary matrix is not saved, nor are the representatives of bars the threshold hid. With cocycles and every bar reported, a dimension-0 cocycle is a whole connected component, so such a file grows quickly with the number of points.

What there is

call draws
Plot.barcode(d), Plot.barcode(d, longest = Some(10)) one bar per class, grouped by degree; essential bars run off to ∞
Plot.diagram(d) (birth, death) per class above the diagonal; essential classes on the ∞ line
Plot.persistenceImage(d, degree), Plot.landscape(d, degree) the vectorizations of Vectorization
Plot.image(img), Plot.grid(stream) a 2-D image or cubical grid as a heatmap
Plot.cubicalChain(img, bar.representative) a cubical cycle or cocycle over its image
Plot.points(points) a point cloud (first two coordinates)
Plot.complex(points, r), Plot.complex(points, r, Cech), Plot.complex(points, r, AlphaShapes) the complex at scale r with the balls whose overlaps it records
Plot.complex(points, stream, r) the cells of any simplicial stream up to r
Plot.cycle(points, bar.representative) a simplicial cycle over its points (a chain, or its cells with coefficients as numbers)
Plot.cocycle(points, bar.representative, at = bar.birth) a cocycle, colored by value, restricted to the complex at at
Plot.circularCoordinates(points, result.theta), Plot.torus(theta1, theta2) circular and toroidal coordinates on a cyclic color map
Plot.points3D, Plot.complex3D, Plot.cycle3D the same in 3-D: drag to turn, scroll to zoom

Anything that takes a diagram also takes a list of bars. A cycle reads best over the complex it lives in:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = Array.tabulate(40)(i => Array(math.cos(i * 0.157), math.sin(i * 0.157)))
val d = Persistence(points, maxDimension = 1, engine = Persistence.Engine.Chunks)
import d.given
val loop = d.dim(1).longest.get
Plot.cycle(points, loop.representative).over(Plot.complex(points, loop.birth)).view()

A cocycle of a bar lives on the complex where the bar dies, so it has edges right across the data; restricted to the complex at the bar's birth (at = loop.birth) it shows the edges that cut the loop as it closes. A result's plotRepresentative(i) draws a cocycle that way, and plotRepresentative(i, Inf) draws it whole.

A slider through the filtration

Plot.filtration is a page with a slider for the scale. On the left, the complex at that scale: the balls around the points and the edges and triangles that have come in by then. On the right, the persistence diagram, where each class is a vertical segment from the diagonal up to the horizontal line that follows the slider, and becomes a point once the line passes its death. Classes that never die grow with the line.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
Plot.filtration(points, max = 1.0).withTitle("A noisy circle").withPlay(10.0).save("filtration.html")
import org.appliedtopology.tda4j.matlab.*;

points = readmatrix('_docs/tutorials/data/noisy-circle.csv');
result = TDA4j.computeFromPoints(points, {'maxDimension', '1'});

result.plotFiltration(1.0).withTitle('A noisy circle').withPlay(10.0).save('filtration.html');
import tda4j
import numpy as np

points = np.loadtxt("_docs/tutorials/data/noisy-circle.csv", delimiter=",")
result = tda4j.persistence(points, max_dimension=1)
page = result.plot_filtration(1.0).with_title("A noisy circle").with_play(10.0)
page.save("filtration.html")

From the command line, tda4j --max-dimension 1 --plot filtration --at 1.0 --output filtration.html points.csv writes the same page.

The page is one HTML file with its script inside: open it in a browser, send it by mail or put it on a web server. It needs no network and no library. Drag the slider, use the arrow keys, or press play (withPlay(seconds) sets how long a sweep takes). It follows the reader's light or dark setting like every page. The scale runs from 0 to max; the Scala call takes the largest scale as max, the facades as their argument. Options of Plot.filtration:

option does
kind = Cech, AlphaShapes another complex (balls of radius equal to the scale instead of half of it)
balls = false no balls
barcode = true the barcode with a movable vertical line instead of the diagram: each bar grows until the line passes its death
stops = true the slider steps through the values at which the complex changes, one step for each change of the picture
start where the slider begins
link = true the diagram (and the barcode) are linked to each other and to the complex, where a chosen class draws its cycle; the pictures zoom
maxCells the page holds every edge and triangle up to max; asked for more than this (200,000 by default), it refuses and says to lower max
canvas up to 20,000 cells the complex is an SVG with axes, one element for each cell. Above that it is a canvas, a flat picture seen from above with an x axis, a y axis and gridlines: a drag pans it, the wheel zooms about the pointer, the numbers and the gridlines follow, and it takes about a seventh of the bytes and a hundredth of the elements. canvas = true or false chooses either way

Plot.filtration3D(points) is the same with the complex in 3-D, a canvas to turn and zoom beside the diagram; result.plotFiltration3D(max) from a result, --plot filtration-3d on the command line. The balls grow with the slider. The frame is fitted to the points, so a ball larger than the picture is cut at its edge. With link = true the canvas is linked like the flat page: a class chosen in the diagram or the barcode draws its cycle in the canvas, pointing at an item of the canvas chooses it, and the items that are chosen get a halo. On a touch screen one finger turns the canvas (it does not scroll the page: scroll from outside it) and two fingers pinch to zoom. Plot.filtrationOf(points, stream, bars) takes a complex and a diagram of your own, for instance a witness complex or one whose diagram you computed with another engine.

Frames, a video and a slide

An interactive page works in a browser and nowhere else, so the same plot also gives still pictures. page.at(0.6) is the picture with the slider at 0.6, page.frames(60) sixty of them from the smallest scale to the largest, and page.saveFrames("frames", 60) writes them as frame-0000.svg and on. The axes are fixed across frames, so nothing jumps when they are played. Each frame is built from the same rules as the page (a cell is shown from the value at which it enters, a class from its birth), so a frame at a scale shows the cells that Plot.complex shows at that scale.

The other languages write the same frames. Python: page.save_frames("frames", 60). JavaScript: chart.saveFrames("frames", 60) on Node.js writes the files, and chart.frames(60) returns the 60 SVG documents as strings, in a browser too. On the command line --frames 60 with --plot filtration --at 1.0 writes them into the folder that --output names (a folder, not a file):

tda4j --max-dimension 1 --plot filtration --at 1.0 --frames 60 --output frames points.csv

The frames are SVG. A video needs pictures: convert them and let ffmpeg join them. A paper-white background (withPalette("print") and withStyle("print")) keeps the video from showing a transparent background as black:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val page = Plot.filtration(points, max = 1.0).withPalette("print").withStyle("print")
page.saveFrames("frames", 60)
pip install cairosvg
python3 -c "
import cairosvg, glob, os
os.makedirs('png', exist_ok=True)
for f in sorted(glob.glob('frames/frame-*.svg')):
    cairosvg.svg2png(url=f, write_to='png/' + os.path.basename(f)[:-4] + '.png', scale=2)"

# an MP4 (H.264, plays in PowerPoint, Keynote and every browser); 12 pictures a second
ffmpeg -framerate 12 -i png/frame-%04d.png -c:v libx264 -pix_fmt yuv420p \
  -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -movflags +faststart filtration.mp4

# or a GIF
ffmpeg -framerate 12 -i png/frame-%04d.png \
  -vf "split[a][b];[a]palettegen=stats_mode=diff[p];[b][p]paletteuse=dither=bayer:bayer_scale=5" filtration.gif

(ffmpeg and cairosvg are separate programs; the commands were run with ffmpeg 6.1 and cairosvg 2.9 on 60 frames of a noisy circle, and give a 1132 by 558 MP4 of 5 seconds at 12 pictures a second.) Chromium or Inkscape make the PNGs just as well, see PNG and PDF. The stills show only the behaviors the library knows. A page with a script of your own (below) is recorded by driving the page itself: this Playwright script moves the slider through its range and takes a screenshot of the page at each step, which ffmpeg joins as above:

// node record.mjs filtration.html shots 60   (npm install playwright)
import { chromium } from 'playwright';
import fs from 'fs';
const [file, dir, count] = process.argv.slice(2);
fs.mkdirSync(dir, { recursive: true });
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1200, height: 640 }, deviceScaleFactor: 2 });
await page.goto('file://' + process.cwd() + '/' + file);
const root = page.locator('.tda4j-ia');
const { n, min, max } = await root.evaluate(el => el.tda4j.controls[0]);
for (let i = 0; i < +count; i++) {
  await root.evaluate((el, name, v) => el.tda4j.set(name, v), n, min + (max - min) * i / (count - 1));
  await root.screenshot({ path: `${dir}/shot-${String(i).padStart(4, '0')}.png` });
}
await browser.close();

In PowerPoint. A slide cannot run the page: PowerPoint has no way to embed HTML and script, and an SVG on a slide is a still picture. What does work is the video: Insert > Video > This Device takes the MP4 and plays it in the slide show (Playback > Start: Automatically starts it without a click). Where the slide should stay still while you talk, put one frame on each of several slides (page.at(0.3), page.at(0.6), ... saved as SVG or PNG): the picture changes when you click, and it is exactly the picture the page shows. A deck can also be made by a script: with python-pptx, slide.shapes.add_movie("filtration.mp4", left, top, width, height, poster_frame_image="png/frame-0059.png", mime_type="video/mp4") embeds the video and a poster frame, and LibreOffice opens the result and shows the poster (the video itself was not played, and nothing here was tried in PowerPoint itself). For a page that really moves in front of an audience, switch to the browser (Alt+Tab, or a hyperlink on the slide to the file). Microsoft's Web Viewer add-in can show a web page inside a slide, but only an https address and with an internet connection, so the page has to be on a server first, and Microsoft has changed what the add-in does more than once: test it on the machine you present from before relying on it.

In reveal.js. The page is plain HTML and script, so a reveal.js deck runs it, and the slide moves with the slider. Either point a slide at the saved page, or paste page.fragment() into the slide's source:

<section><iframe class="r-stretch" data-src="filtration.html" style="width:100%;border:0"></iframe></section>

Pages written by separate runs can share one deck: each page's element ids carry a token drawn per run, so a second page's slider never drives the first's picture. A page fits the room it is given: the panels sit side by side at their own size (1132 pixels for the two default ones) when there is room, shrink together when there is less, and stack below about 650 pixels. The arrow keys move a focused slider and leave the slide where it is. This was tried in Chromium with reveal.js 5.2.1; Firefox and Safari were not, and a fragment put in with innerHTML does not run its script (the browser skips it).

Interactivity of your own

The page is built from small values, with the same chained style as the rest of the plots. A control is a slider with a name. A behavior says what a control does to an item of a mark, and a panel is a figure (or a 3-D scene) with behaviors attached to the items of its marks, either one for all items or one for each, as paints work. An Interactive is panels and controls side by side:

behavior the item
Behavior.shownFrom(c, v), shownUntil(c, v), shownBetween(c, a, b) is there while the value of control c is at least v, below v, or from a up to but not including b
Behavior.followsX(c), followsY(c, lo, hi, ends), followsZ(c, lo, hi, ends) has this coordinate equal to the value of c, held between lo and hi: a movable line, a bar that grows, and in a 3-D scene a plane that rises (followsZ)
Behavior.radius(c, factor) for the discs of a mark: radius is factor times the value (data units; linear axes only)
Behavior.custom(kind, c, args*) whatever your script says (below)

a + b puts several behaviors on one item. This shows a point cloud one point at a time, and writes the same thing as 40 still frames:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = Array.tabulate(40)(i => Array(math.cos(i * 0.157), math.sin(i * 0.157)))
val cloud = points.map(p => (p(0), p(1))).toIndexedSeq

val reveal = Panel(Plot.points(points)).reactEach(
  Mark.Points(cloud, IndexedSeq(Paint.Series(1)), radius = 6),
  cloud.indices.map(i => Reaction(Vector(Behavior.shownFrom("t", i.toDouble))))
)
val page = Interactive().withSlider("t", 0, 39).withPanel(reveal).withTitle("One point at a time")

page.save("reveal.html")
page.saveFrames("reveal-frames", 40)

Behaviors that the library cannot know are written in JavaScript: withScript(js) runs your script on the page, where tda4j is the page's controller with get(name), set(name, value), onChange(name, f) and reactor(kind, f), which says what a Behavior.custom(kind, ...) does to its item (f(item, behavior, value), item.el the SVG element). Each change of a control is also announced as a tda4j:change event on the page's element, for anything else on the page. A frame shows the item as it was drawn, without the effect of a custom behavior. A behavior the page cannot carry out (a radius on a logarithmic axis) is refused when the panel is built, with the reason.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = Array.tabulate(40)(i => Array(math.cos(i * 0.157), math.sin(i * 0.157)))
val cloud = points.map(p => (p(0), p(1))).toIndexedSeq

val glowing = Panel(Plot.points(points)).react(
  Mark.Points(cloud, IndexedSeq(Paint.Series(2)), radius = 8),
  Behavior.custom("glow", "t")
)
Interactive()
  .withSlider("t", 0, 1)
  .withPanel(glowing)
  .withScript("tda4j.reactor('glow', (item, behavior, v) => { item.el.style.opacity = v; })")
  .save("glow.html")

Every plot tweak of this page reaches every panel: page.withPalette("print"), withStyle, withTextScale, withSetting. Panel.sweepDiagram(figure, control) and Panel.sweepBarcode(figure, control) turn a diagram or a barcode into the sweeping panel of this page, for a page of your own.

Exploring a barcode

Plot.exploreOn(points, bars) is a page of three pictures that know about each other: the point cloud, the persistence diagram and the barcode. Point at a class in the diagram or the barcode and it lights up in the other one, and its representative cycle is drawn on the points. A click keeps the class chosen (a shift-click adds another, a click on the background lets them all go), dragging a rectangle over a diagram or a barcode chooses every class it touches, and the page lists what is chosen under the pictures. Every picture zooms and pans.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)
Plot.exploreOn(points, d).withTitle("A noisy circle").save("explore.html")
import org.appliedtopology.tda4j.matlab.*;

points = readmatrix('_docs/tutorials/data/noisy-circle.csv');
result = TDA4j.computeFromPoints(points, {'maxDimension', '1'});

result.plotExplore().withTitle('A noisy circle').save('explore.html');
import tda4j
import numpy as np

points = np.loadtxt("_docs/tutorials/data/noisy-circle.csv", delimiter=",")
result = tda4j.persistence(points, max_dimension=1)
result.plot_explore().with_title("A noisy circle").save("explore.html")

On the command line, tda4j --max-dimension 1 --plot explore --output explore.html points.csv writes the same page. Plot.explore(bars) is the diagram and the barcode without the points, and Plot.filtration(points, link = true) is the slider page above with the same links, so that a class chosen in the diagram draws its cycle on the complex at the scale the slider shows. The cycles are the bars' representatives (Persistence records cycles by default; a cocycle is drawn as it is). A page holds every cell of every cycle, so maxCycleCells (20,000) keeps the most persistent bars' cycles and leaves the rest of the classes lit up in the diagram and the barcode without a cycle; the cloud's subtitle says so.

Zoom and pan. Each picture has buttons in its corner: + and − zoom about the middle, 1:1 shows everything, and Ctrl (Cmd on a Mac) with the mouse wheel zooms about the pointer, which keeps the point under it where it was. Dragging pans; in a picture where dragging also chooses classes, the button pan switches what a drag does. On a touch screen two fingers pinch and drag the picture (the distance between them zooms, their midpoint pans), one finger scrolls the page as it does everywhere, and a tap chooses. A picture where a drag chooses has a touch button: while it is on, one finger draws the rectangle (and a second finger landing is a pinch, which drops it). From the keyboard, Tab reaches a picture; + and - zoom about the middle, 0 shows everything, and the arrow keys pan where a drag pans (Shift goes further). In a picture where a drag chooses, the arrow keys move a cross over it instead, ] and [ (or Page Down and Page Up) put the cross on the next and the previous item the rectangle can choose, left to right and top to bottom, Home and End on the first and the last, Enter sets one corner of the rectangle and a second Enter chooses what it touches (Shift adds to what is chosen), and Escape lets go. Two items make a rectangle, however far apart they are: step to one, Enter, step to the other, Enter. The axes follow: new gridlines and numbers for the range shown, written as the plot writes them, while lines keep their width and points their size. Zooming stops at 1/200 of the picture, and the picture of an equal-aspect plot keeps its aspect (the barcode zooms along the filtration only, and keeps all its rows). What the window cuts away cannot be pointed at or chosen. A page that only zooms needs no slider: Interactive().withPanel(Panel(figure).zoomable()), or page.zoomable() on any page, which makes zoomable every flat panel whose axes the page can draw again: linear, logarithmic, square-root, symmetric-log and reversed axes, with their number formats, number style, slanted labels and minor ticks. Three things it cannot draw again: a transform of your own, a logarithmic axis with a -∞ line for what is at 0, and a number format other than %f and %e (with the flags -, +, 0 and ,, a width and a precision). Panel.zoomable refuses them with the reason, and zoomable() leaves those panels as they are. The 3-D canvases have a zoom of their own.

Stills. A viewer's choice is a value like a slider's: page.at(PageState().select("class", 3).zoom(1, Window(-0.1, 0.6, 0.1, 0.8))) is the picture with class 3 chosen (the key is the position of the bar in the list given) and the second picture, the diagram, showing that range (an equal-aspect picture widens one range of a window to keep its aspect, as the page does).

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)
val page = Plot.exploreOn(points, d)
val chosen = d.bars.indices.maxBy(k => d.bars(k).persistence)
page.at(PageState().select("class", chosen).zoom(1, Window(-0.1, 0.6, 0.1, 0.8))).save("explore-still.svg")

A rectangle that a viewer has dragged out is part of the state too: PageState().brush(panel, Window(x0, x1, y0, y1)) draws it in a brushable panel, a dashed box in the picture's own units, and select gives what it touches, as the page does. Both are needed to show what a viewer who dragged a rectangle sees.

Selections of your own

A selection is to a viewer's pointer what a slider is to a slider's value: a named set of whole-number keys that panels choose from and react to. Panel.selecting(mark, name, keys) makes the items of a mark choose the key keys(i) while the pointer is on them and lights a translucent halo round them while their key is chosen by anyone, brushable(name) lets a drag choose (on a 3-D canvas the box button makes a drag draw the rectangle, in the plane of the view, instead of turning the picture), and Behavior.selected(name, key) shows an item (a cycle, a label) only while a key is chosen, together with shownFrom and followsY, so a page can have both a slider and a selection. Interactive.withSelection(Selection(name)) declares the selection (withList, withLabels(...), clickOnly, hoverOnly change how it behaves and what the page writes under the pictures). On the page, tda4j.selection(name) gives the chosen keys to a script of your own, tda4j.onChange(name, f) calls f with the keys at every change, and the change is also announced as a tda4j:change event whose value is the array of keys. The zoom has tda4j.zoom(panel, [x0, x1, y0, y1]), tda4j.window(panel) and tda4j.resetZoom(panel) (panels counted from 0), and each new window is announced as a tda4j:zoom event. The rectangle of a brushable panel is tda4j.brush(panel, [x0, x1, y0, y1]) (no argument clears it), and tda4j.pointAt(panel, clientX, clientY) is the data under a point of the window. Plot.explore is built from exactly these pieces, so it is the example to read.

These pages are checked in Chromium, Firefox and WebKit (Safari's engine) on every change: the page's picture at each state is compared with the still the library draws for the same state. Touch gestures are checked in Chromium with touch events that a script sends, not on a phone, and not in Firefox or WebKit; Safari on an iPhone was not tried. What these pages do not have: a rectangle on a 3-D canvas lies in the plane of the view, so it is dropped when the picture turns, zooms or pans, and a touch screen draws a rectangle only after the touch or box button (one finger scrolls the page or turns the picture otherwise).

Customizing a plot

A plot is an immutable value, and each customization returns a new plot, so they chain:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val loops = Plot.diagram(d.dim(1))
  .withLabels(title = "The loops of a noisy circle", x = "birth", y = "death")
  .withXYScale(Transform.Log10)
  .withSize(640, 640)
loops.view()

The design follows the grammar of graphics: the plot constructors (Plot.barcode, Plot.diagram, ...) choose what is drawn, and the with... methods change the scales, the labels, the colors and the look, each independently of the others. Every argument is optional, and only what is given changes: withLabels(x = "birth (cm)") leaves the title as it is. Changes of different parts can come in any order; of the same part, the later one wins, keeping the rest of the earlier one (.withLabels(title = "A").withLabels(title = "B") titles the plot B).

to change method the same as a value
the words: title, subtitle, axis labels, legend heading, color bar title withLabels(title = ..., subtitle = ..., x = ..., y = ..., legend = ..., color = ...) Labels(...)
the size in pixels withSize(960, 540), or withSize(width = 900) to keep the height Size(...)
an axis: scale, limits, ticks, number format, gridlines withXScale(...), withYScale(...), withXYScale(...) Scale.x(...), Scale.y(...), Scale.xy(...)
the scale of a heatmap or a cocycle's values withColorScale(min = ..., max = ..., stops = ..., transform = ...) Scale.color(...)
the color, legend label and marker of a homological degree withDegree(1, color = "#c2185b", label = "loops", shape = Shape.Diamond) Scale.degree(...)
the color scheme withPalette(Palette.reference) the Palette itself
fonts, size of text and marks, gridlines, the legend's place, the background withStyle(Style.slides) the Style itself
a box round the legend, and its entries in columns withLegendBox(box = true, background = "white", columns = 2) Guide.legend(...)
the markers of points: shape, size, opacity, open or filled, the edge withPoints(shape = Shape.Star, size = 6, fill = false, edgeWidth = 0) Geom.points(...)
a barcode's bars, a complex's edges, triangles and balls withSegments(width = 3), withPolygons(opacity = 0.3), withDiscs(...), withLines(width = 3) Geom.segments(...), Geom.polygons(...), Geom.discs(...), Geom.lines(...)
each kind of text: size, weight, slant, alignment, font, color withText(TextRole.Title, size = 18, align = Anchor.Middle) Text(TextRole.Title, ...)
gridlines, axis lines, tick marks, a frame withGridLines(dash = Dash.Dotted), withAxisLines(...), withTickMarks(length = 4), withMinorTickMarks(...), withMinorGridLines(...), withFrame() Lines.grid(...), Lines.axis(...), Lines.ticks(...), Lines.minorTicks(...), Lines.minorGrid(...), Lines.frame(...)
the fill of the plot area, the diagonal and its shaded half plane withPanel(color = "#f4f4f4"), withDiagonal(shade = false) Guide.panel(...), Guide.diagonal(...)
which side an axis is on withXScale(position = Side.Top), withYScale(position = Side.Right) Scale.x(position = ...), Scale.y(position = ...)
what is drawn plot + mark: Mark.Rule.horizontal(0.1), Mark.Diagonal(offset = 0.1), your own Mark.Points(...)

The right-hand column matters when a look is shared. Each change is also a tweak, a value: you can keep it in a val, combine tweaks with + and add the result to any plot, of any kind, with +. The look of a paper or a talk is then one val (see The look below). A tweak that means nothing for a plot (an axis of a 3-D scene) says so; one that merely has nothing to change (a color scale on a barcode) leaves the plot as it is, so one bundle fits every plot.

Labels, size and scales

An axis takes a scale (Transform.Log10, Transform.Sqrt, or Transform.SymLog(linear), logarithmic away from zero and linear within linear of it), the ends of the visible range, the tick positions and a printf pattern for the tick numbers, and can drop its gridlines or disappear altogether:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val barcode = Plot.barcode(d)
  .withXScale(max = 2, breaks = Seq(0, 0.5, 1, 2), format = "%.1f")
  .withYScale(grid = false)
barcode.save("barcode.svg")

min and max move one end each, so withXScale(max = 2) keeps the plot's own lower end.

Every value has a place on every scale. On a log axis what is at exactly 0, such as an H0 bar's birth, sits on a -∞ line just below the lowest number, labelled -∞ as an essential bar's end is labelled ∞; a bar born there starts from the line. A log axis with a negative value (a sublevel set of a function that goes below zero) is drawn as a symmetric log: logarithmic away from zero, linear within the smallest magnitude on the axis, zero in its place, and a line of small print under the plot says so. A square root keeps the sign, so a negative value is mirrored, and Transform.SymLog(linear) sets the linear stretch yourself. Only a value that is not a number at all is left out, and the small print counts it. withXScale(minusInfinity = false) leaves what is at 0 out of a log axis instead (counting it), and minusInfinity = true keeps the line with nothing on it, so that panels line up (Board.shared() does that for you). The diagonal of a diagram is drawn in the plot's own scales, so it is still the line y = x on a log-log diagram, and it starts where the numbers do, not at the -∞ line.

Colors

Homological degree k always has the same color and marker shape: degree 0 teal, degree 1 gold, degree 2 brick, so H1 looks the same in every plot whichever degrees are shown. The default palette is TDA4j's Teal & Gold, stepped for charts and checked for color-vision deficiencies (the first three degrees stay distinguishable side by side for every common deficiency). Palette.reference is a neutral alternative, and Palette.print is for a paper: black text on a background of exactly white, where the default's cream would print as a grey patch (Palette.grayscale is that without color, Palette.okabeIto is the eight colors of Okabe and Ito on the same white), and Palette.clear is black or white for a figure with no background (see For a paper). A palette recolors the whole plot, heatmaps and cocycles included, and you can make your own:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val onWhite = Palette.brand.withSurface("#ffffff") // a figure for a white page
val bold = Palette.brand.withSeries(Seq("#222222", "#c2185b", "#00796b"))

val diagram = Plot.diagram(d).withPalette(bold)
val image = Plot.persistenceImage(d, 1).withPalette(Palette.reference)
val paper = Plot.barcode(d).withPalette(onWhite)

One degree can be changed wherever it appears, in the marks, the legend and the dark mode alike, without touching the rest, and whichever palette the plot has:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val diagram = Plot.diagram(d)
  .withDegree(0, label = "components")
  .withDegree(1, color = "#c2185b", label = "loops", shape = Shape.Diamond)
  .withLabels(legend = "Homology")

Heatmaps (persistence images, images, cubical grids), cocycles and circular coordinates have a color scale, which maps the values to colors: heatmaps and cocycles through the palette's sequential and diverging ramps, circular coordinates through a cyclic one. withColorScale sets its limits, so that two plots are read on one scale, and the colors of a sequential ramp (ColorScale.viridis, ColorScale.greys, or any list of colors, light to dark) and how values are spread along it (Transform.Sqrt for a heavy-tailed image; the color bar then labels round numbers between its ends, each where the transform puts it). A cocycle's scale is symmetric about zero, so it takes only a max.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val image = Plot.persistenceImage(d, 1)
  .withColorScale(max = 0.05, stops = ColorScale.viridis, transform = Transform.Sqrt)
  .withLabels(color = "density")

The look

A Style holds what is not data: the font, a factor on the size of text and one on the size of markers and lines, the gridlines, where the legend goes (see The legend) and whether there is a background at all. Style.slides is a projector-sized preset (text and marks 30% larger); Style.print and Style.clear are for a paper and for a page of either color. A style replaces the plot's whole style; to change one setting of a style, copy it. Keep everything that makes a look a val, with +, and add it to every plot, of any kind:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val house = Style.slides.copy(legend = LegendPosition.Bottom) + Palette.reference + Size(960, 540)

Plot.barcode(d).withLabels(title = "Barcode") + house
Plot.diagram(d).withLabels(title = "Diagram") + house
Plot.points3D(points) + house

(Theme, which save and html take, is a different thing: whether the colors are light, dark, or follow the reader's own setting.)

Markers

A marker is a shape, drawn filled in its degree's color or open, with an edge around it: by default a ring of 2 pixels in the background's color, which keeps overlapping markers apart. Every part of that can be changed, for all the points of a plot or for one degree, and the edge can be taken away. The plots give each degree its own shape (circle, triangle, square, diamond), so that a diagram reads without color; there are more to choose from: Circle, Dot, Square, Triangle, TriangleDown, TriangleLeft, TriangleRight, Diamond, Pentagon, Hexagon, Star, the strokes Plus, Cross, VLine and HLine, and text, Shape.Glyph("★"), drawn in the marker's color.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val dense = Plot.diagram(d).withPoints(size = 3.5, opacity = 0.6, edgeVisible = false)
val open = Plot.diagram(d).withDegree(1, marker = MarkerStyle(fill = Some(false), size = Some(6)))
val stars = Plot.diagram(d).withPoints(shape = Shape.Glyph("★"), size = 7, edgeWidth = 0)

size is the radius in pixels, before the style's mark scale; opacity covers the marker and its edge; fill = false draws an open marker, an outline in its own color 1.5 pixels wide; the edge has a width (0 for none), a color or a palette role, an opacity and a dash, and edgeVisible = false takes it away. A plus, a cross and a bar are strokes: their edge is their color and their width is the edge's. A degree's markers (Scale.degree(k, marker = MarkerStyle(...))) win over the plot's marker settings, which win over the default. A 3-D scene's points are round and filled, and take a size, an opacity and an edge.

As text, a shape is a name (triangle-down, star, plus, ...), a one-letter code of matplotlib (o . ^ v < > s p h * + x D | _), a number of R and ggplot's pch (pch:16, or a bare 0 to 25: 0 to 14 are open shapes, 15 to 25 filled, the composite ones, 7 and 9 to 14, drawn as their outer shape) or glyph:text; any other single character is a glyph, and a code wins over a letter (glyph:x for the letter). marker.shape=pch:1 is an open circle: withSetting("marker.shape=pch:1"), withSetting("marker.edge-width=0"), withSetting("degree-1.size=6"), --set marker.shape=triangle-down.

The legend

The legend goes beside the plot (LegendPosition.Right, the default, or Left), above or below it (Top, Bottom, in rows that wrap), or inside the plot area at a corner (UpperLeft, UpperRight, LowerLeft, LowerRight), taking no room; or nowhere (Hidden). A persistence diagram puts it at the lower right by itself, below the diagonal where no point can be, in the shaded half plane. withLegend("right") or Style(legend = LegendPosition.Right) puts it beside the plot again; a style that does not name a place leaves each plot's own. A corner of a barcode over its bars covers some of them: choose the place for the plot, or give the legend a box.

A legend has no box unless you ask for one. withLegendBox(box = true) gives it the page's own color, a little see-through (opacity 0.9), and a thin frame, which keeps it readable over data wherever it is; background = "white" (or backgroundPaint) and opacity set the fill, frame = true, frameColor and frameWidth the line round it, and padding the room inside (6 pixels, growing with the legend's text size). A fill or a frame alone is a box of that kind, box = false takes it away. columns puts the entries in that many columns, a column filled before the next (seven entries in three columns are 3, 3 and 1); above or below the plot the columns line up as a grid beside the heading.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val d = Persistence(Array.tabulate(16)(i => Array(math.cos(2 * math.Pi * i / 16), math.sin(2 * math.Pi * i / 16))))
Plot.barcode(d).withLegend("upper-right").withLegendBox(box = true)
Plot.diagram(d).withLegend("bottom").withLegendBox(background = "white", columns = 3)

A legend takes at most two fifths of the figure's width beside the plot and at most the plot's width above, below or inside it: the columns that would take more are given up, so a legend never runs off the figure or over the plot.

The bars of a barcode

Plot.barcode(d, order = BarOrder.Persistence) sorts the bars of each degree longest first (Birth, the default, sorts by birth, Death by death); result.plotBarcode("persistence") is the same from MATLAB. withSegments(width = 3) sets their thickness in pixels.

Finer control: text, lines, the plot area, the sides of the axes

The style sets what applies to the whole plot. Each piece of text has a role, and each can be changed alone: Title, Subtitle, AxisLabel, TickLabel, Legend (the entries), LegendTitle, ColorTitle (the title of a color bar; its numbers are TickLabel), Note (the small print under a plot), Caption (the line under a plot, below) and Tag (the letter of a panel). A text has a size in pixels (before the style's text scale, so Style.slides still scales it), a weight, a slant, a font of its own, a color, and, for a title, subtitle, axis label and note, an alignment along the plot area. The tick labels of the x axis can be slanted by an angle. The margins follow the text: a larger tick label makes room for itself.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val figure = Plot.diagram(d)
  .withLabels(title = "Loops", subtitle = "a noisy circle", x = "birth", y = "death")
  .withText(TextRole.Title, size = 20, align = Anchor.Middle)
  .withText(TextRole.Subtitle, italic = true, align = Anchor.Middle)
  .withText(TextRole.AxisLabel, weight = Weight.Bold)
  .withText(TextRole.TickLabel, size = 9)
  .withGridLines(dash = Dash.Dotted)
  .withTickMarks(length = 4)
  .withMinorTickMarks(length = 2)
  .withFrame()
  .withPanel(color = "#f4f4f4", opacity = 1.0)
  .withDiagonal(shade = false, dashed = true)
  .withXScale(position = Side.Top)

The lines are the gridlines, the axis lines, the tick marks and a frame around the plot area, each with a width, a color or a palette role (so that it follows the theme), a dash (Dash.Solid, Dashed, Dotted) and an opacity. Minor tick marks, minor gridlines and the frame are not drawn unless asked for, and giving any of them a setting asks. On a log axis the minor ticks are the whole numbers of each decade that are not ticks; on any other axis, the halves between two ticks. Tick marks point out of the plot (TickDirection.Out) or into it, and the numbers move out of their way. A tick mark asked for with no length is 4 pixels long.

Guide.panel fills the plot area, behind the gridlines. Guide.diagonal restyles the diagonal of a persistence diagram and its shaded half plane (shade = false for none, shadeColor, shadeOpacity); a figure without a diagonal is left as it is. Scale.x(position = Side.Top) puts the x axis above the plot, with its numbers, label and tick marks, and Scale.y(position = Side.Right) the y axis at the right, the legend moving out past it.

Each of these is also a value you can keep in a val and add to any plot; changes of the same element keep what the earlier ones set, and tweaks of different elements come in any order, a Style included, which never undoes them.

As text. MATLAB, Java and the command line (--set) write the same changes as element.property=value:

element properties
title, subtitle, axis-label, tick-label, legend, legend-title, color-title, note, caption, tag size, weight (light, normal, medium, semibold, bold), italic, align (start, middle, end), angle (tick labels only), font, color, limit (the longest the text may be, in pixels)
grid, minor-grid, axis-line, frame visible, width, color, dash (solid, dashed, dotted), opacity
ticks, minor-ticks length, direction (out, in), visible, width, color, opacity
panel color, opacity, visible
legend-box background (a color, or none for no box), opacity, frame (a color, or none), frame-width, padding (pixels), columns
diagonal shade (none or a color), shade-opacity, color, width, dashed
marker shape (a name, a matplotlib code, pch:N, glyph:text), size, opacity, fill, edge-width (0 for none), edge-color, edge-opacity, edge-dash, edge-visible
degree-0, degree-1, ... color, dark-color, label and the marker properties
segments, polygons, discs, lines width, opacity for segments; opacity for polygons and discs; width for lines
x-axis, y-axis the side alone (x-axis=top, y-axis=right), or side, reverse (true runs the axis backwards), padding (the room around the data, as a fraction of their extent), min, max, format, crosses-at (the value of the other axis it goes through)
aspect the length of a y unit over an x unit (aspect=1 for equal units), or free
numbers locale (de, fr, sv, ...), decimal, grouping, minus (space is a space)
size width, height: pixels, or a number with a unit, 3.4in, 8.6cm, 86mm, 245pt
camera azimuth, elevation (degrees), zoom (0.2 to 8), of a 3-D scene

fig.withSetting("title.size=18"), fig.withSetting("grid.dash=dotted") and java -jar tda4j-assembly.jar --plot diagram --set title.size=18 --set ticks.length=4 ... are the same changes. A name that is not one, a number that is not a number and a setting a plot cannot have (a tick label of a 3-D scene, which has a title, a subtitle and a hint) are errors that say what to write instead.

The axes: direction, room, shape and scales of your own

Scale.x(reverse = true) runs an axis backwards, the way a depth or a rank is drawn: the larger numbers are at the left (or at the bottom). Everything drawn in the plot follows, the half plane below the diagonal of a persistence diagram included, and the boxes of a heatmap stay boxes. padding is the room left around the data, as a fraction of their extent (a plot has 0.04 of it on each side; 0 puts the first point on the axis). withAspect(2) makes a y unit twice as long as an x unit on the page, withAspect(1) makes them equal (a persistence diagram begins so), and withAspect(free = true) lets the units differ.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

// the bars from the largest scale down, with no room beyond the data on the x axis
val backwards = Plot.barcode(d).withXScale(reverse = true, padding = 0)

// a scale of your own: the cube root, which spaces 1, 8 and 27 evenly
val cubeRoot = Transform.Custom("cube root", math.cbrt, v => v * v * v)
val cubic = Plot.barcode(d).withXScale(cubeRoot)

// the units of a diagram freed from each other
val loose = Plot.diagram(d).withAspect(free = true)

A scale of your own gives a name (the one messages use), the map to the line and the map back, which must undo each other; the ticks are round numbers of the data, as on a square-root axis. Keep the functions in a val: two axes are on one scale (for Board.shared()) when they hold the same functions.

An axis through a value. An axis is drawn at the bottom (or the top) of the plot and at its left (or right). For data that go negative, crossesAt draws it through a value of the other axis instead: Scale.x(crossesAt = 0) is the x axis through y = 0, Scale.y(crossesAt = 0) the y axis through x = 0, each value in the units of the axis it crosses (a log axis takes the data's own number, not its logarithm). The numbers stay beside the line, below it or to the left of it, or above it and to the right when the axis is given the other position; the tick marks start on it and the gridlines still run across the plot. The axis label stays at the edge, where the data are not, and the margin the numbers needed is given back to the plot. reverse is followed, so is any scale.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.plot.*

// a ring of points drawn round the origin, as a mathematician draws it
val points = Array.tabulate(40)(i => Array(math.cos(i * 0.157), math.sin(i * 0.157)))
val ring = Plot.points(points).withXScale(crossesAt = 0).withYScale(crossesAt = 0)

A value the other axis does not show (a plot of positive numbers asked to cross at 0) or cannot place (0 on a log axis) leaves the axis at the edge, and a line of small print under the plot says so, so one house style with crossesAt fits every plot. x-axis.crosses-at=0 and y-axis.crosses-at=0 are the same as settings, withXCrossesAt(0) and withYCrossesAt(0) from MATLAB.

Numbers

Numbers sets how the numbers of the tick labels and the color bar are written: the decimal separator, a mark between groups of three digits, and the minus sign. Numbers.locale("de") takes what a locale writes (a comma and a hyphen for German, a comma and a true minus sign − for Swedish; the digits stay 0 to 9, so Arabic has a point, not its own decimal separator); the symbols can also be given one by one. Anything that is not a number, such as an H0 in a legend, is left alone.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val german = Plot.diagram(d).withLocale("de")
val typographic = Plot.diagram(d).withNumbers(decimal = ",", minus = "−", grouping = " ")

A long text can be cut: Text(TextRole.Legend, limit = 120) ends a legend entry that would be longer than 120 pixels in an ellipsis, and the whole text is the tooltip of what is left. The renderer has no font metrics, so it estimates the length of a text letter by letter from the advance widths of Helvetica (for sans-serif, system-ui, Arial and the like), Times (serif) or a fixed width (monospace); a font with other proportions is cut some characters from where the estimate puts it. The legend makes room for the same estimate of its widest entry (TextWidth.of(text, size)).

A caption, a panel tag and a description

Labels(caption = ...) puts a line under the plot, at the left of the plot area, and takes its room; tag puts a short label in the corner of the figure, in a larger, semibold face, the way a journal letters its panels; description is what a screen reader says of the plot (the <desc> of the SVG). A barcode and a diagram describe themselves, with their counts by degree, unless you give another. Board.tagged() letters the panels of a board (a), (b), ...; tagged("%s.", "A") writes A., B., and the sequence "1" counts.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val one = Plot.diagram(d)
  .withCaption("Source: a noisy circle")
  .withDescription("One long-lived loop, far from the diagonal")
val board = Plot.side(Plot.diagram(d), Plot.barcode(d)).tagged()

A 3-D scene has none of the three; asking says so.

Sizes in the units of a paper

A figure's size is in pixels, 96 to the inch. Size.inches(3.4, 2.6), Size.cm, Size.mm and Size.pt are the sizes in the units of a journal's template (Size.pt(245) is a column), and size.width=3.4in says the same as a setting. Add the size with + as any tweak: Plot.diagram(d) + Size.inches(3.4, 2.6). The text keeps its size in pixels, so check it against the column.

The camera of a 3-D scene

A 3-D scene is drawn from one view in a saved .svg, and on a page it starts from that view and can be turned (drag) and zoomed (scroll). Camera(azimuth, elevation, zoom) sets it: the azimuth turns the scene around the vertical axis and the elevation raises the eye above the horizon, both in degrees (from the front, azimuth = 0, elevation = 0; the default view is -35 and 25), and the zoom is how close, from 0.2 to 8 (2 shows the scene twice as large, round the middle of the plot). Only what is given changes. A 2-D figure has no camera and says so.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val helix = Array.tabulate(60)(i => Array(math.cos(0.3 * i), math.sin(0.3 * i), i / 30.0))
val scene = Plot.points3D(helix).withCamera(azimuth = 20, elevation = 10, zoom = 1.3)
scene.save("helix.svg")

From MATLAB it is scene.withCamera(20, 10, 1.3) and scene.withSetting('camera.zoom=1.3'); on the command line, --plot input-3d --set camera.azimuth=20 --set camera.zoom=1.3.

A scene seen from above (azimuth = 0, elevation = 90) is a flat picture, and withAxes gives it an x axis and a y axis with numbers at round values of the plane's coordinates, gridlines at the numbers and what lies beyond the axes clipped. On a page the numbers and the gridlines follow the pan and the zoom; a scene with axes asks for the view from above and says so otherwise.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val flat = Scene(
  Vector(Layer.Points(IndexedSeq((-2.0, -1.0, 0.0), (0.0, 1.0, 0.0), (2.0, 0.0, 0.0)), IndexedSeq(Paint.Ink), 4.0)),
  azimuth = 0,
  elevation = 90,
  turns = false
).withAxes
flat.save("flat.svg")

The axes take what a figure's take, with three exceptions below. withXLabel and withYLabel (or Labels(x = ..., y = ...)) write the names beside the numbers. withXScale, withYScale and withXYScale (or Scale.x/y/xy) set an axis:

option what it does on a flat picture
transform Log10, Sqrt or SymLog(c). A log axis needs positive numbers; a symmetric log keeps zero and the negative ones. The picture is the data after the transforms, with one scale on both axes
min, max, padding the range the picture opens on, in data units, and what the 0 key returns to. An end that is not given is the data's, padded by padding (default 0.04) of their extent. The picture keeps equal units on both axes, so the range is widened to the shape of the plot area, and the pan and the zoom move off it. Without any of the three, the picture is fitted to its points
breaks, format where the numbers stand (those that are in view) and a printf pattern for them: %f and %e, with the flags -, +, 0 and ,, a width and a precision
reverse runs the axis the other way: the points, the numbers and the gridlines are mirrored together
visible false leaves out the axis: its line, numbers, label and gridlines, and the room they took
grid false removes the gridlines of an axis; Lines.grid(...) restyles them

The page writes the same numbers as the file, and they follow the pan and the zoom. Three things stay with a Figure and are refused here, with the way out: position and crossesAt (the axes of a canvas stay at the foot and the left edge of its plot area), and minusInfinity (a canvas that pans has no place for a -∞ line: a point at zero on a log axis is refused, and SymLog keeps it); so is a transform of your own, which has no ticks a page can draw. A control that moves an item (Behavior.Follows) works on any axis: its value goes through the axis, so on a square-root axis the item is at the root.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val birth = IndexedSeq.tabulate(12)(i => math.pow(10, -2.0 + 0.4 * i))
val loglog = Scene(
  Vector(Layer.Points(birth.map(b => (b, 3 * b, 0.0)), IndexedSeq(Paint.Ink), 4.0)),
  azimuth = 0,
  elevation = 90,
  turns = false
).withAxes
  .withXYScale(Transform.Log10)
  .withLabels(x = "birth", y = "death")
loglog.save("loglog.svg")

A range, the breaks and a format, and an axis that runs backwards:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val spread = IndexedSeq.tabulate(20)(i => (i - 4.0, 1.0 + 0.4 * i, 0.0))
val window = Scene(
  Vector(Layer.Points(spread, IndexedSeq(Paint.Ink), 4.0)),
  azimuth = 0,
  elevation = 90,
  turns = false
).withAxes
  .withXScale(min = 0.0, max = 8.0, breaks = Seq(0.0, 2.0, 4.0, 6.0, 8.0), format = "%.1f")
  .withYScale(reverse = true)
  .withTitle("Opens on x from 0 to 8")
window.save("window.svg")

From MATLAB, scene.withXLabel('birth').withXScale('log') and scene.withXRange(0, 8).

For a paper, and for a page of either color

Two looks are ready-made, each a palette and a style, and they differ in what is behind the figure.

Palette.print and Style.print are for a figure that has a white background of its own, as in a paper, in a saved file too. The palette is black text and axes on a surface of exactly white (the default's cream would print as a grey patch); its degree colors stay apart for every common color vision and read on white (blue, vermillion and bluish green for degrees 0 to 2, checked on all pairs), and its heatmap ramp darkens steadily, so it keeps its order on a grayscale printer. It has one look: the dark theme draws the same figure. The style names fonts that converters and publishers know (Helvetica, Arial) instead of the browser's own system-ui.

Palette.grayscale is print with no color at all, for a paper that prints in black and white. Degrees are told apart by lightness (a dark, a light and a middle gray first, each dark enough to show on white) and by the marker shapes and the legend, which every palette keeps: past four degrees the grays run out, so rely on the shapes. A heatmap uses ColorBrewer's Greys, darker for larger. A diverging scale (a cocycle's values) is a dark gray against a middle gray around a light middle, a weaker cue for the sign than a hue; use Palette.print for those when color is available.

Palette.okabeIto is the color-blind-safe palette of Okabe and Ito on print's white surface and black ink, with the same heatmap ramp and the same blue against vermillion for a diverging scale. Degrees 0 to 2 are its blue, vermillion and bluish green, which stay apart side by side for every common color vision; the next colors are orange, sky blue and reddish purple, then yellow and black. Orange and sky blue are lighter than a thin mark wants against white, and yellow barely shows on it, so they come last: past the third degree, rely on the marker shapes and the legend. Like print it has one look for both themes, as Okabe and Ito defined their colors for a light background. The palette is validated as accessible on white only; on any other background the checks no longer hold.

Palette.clear and Style.clear are for a figure with no background, that takes the color of what is behind it. The style draws none, on a page as in a file (a saved .svg has none anyway, unless its style asks for one). The palette has two looks, which the theme picks: pure black elements for a light page (Theme.Light, what an .svg file gets) and pure white ones for a dark page (Theme.Dark), each with degree colors chosen to read on its own page color. Theme.Auto follows the reader's setting, which is right only where the page does too. Without the style, a figure shown on a page keeps the white or the black background of its mode.

A size is in pixels of 1/96 inch, and text is 11 to 15 pixels. Give the figure the size it has on the page and place it at that size, and its text comes out at the size the journal asks for: a 3.4-inch column is 326 pixels, in which tick labels are 8.25 pt. For a serif face to match the text of the paper, copy the style:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val paper = Palette.print + Style.print + Size(326, 260)
val serif = Palette.print + Style.print.copy(font = "'Times New Roman', Times, serif") + Size(326, 260)
val overlay = Palette.clear + Style.clear

Plot.diagram(d).withLabels(x = "birth", y = "death") + paper
Plot.barcode(d) + serif
(Plot.diagram(d) + overlay).save("for-a-light-page.svg")
(Plot.diagram(d) + overlay).save("for-a-dark-page.svg", Some(Theme.Dark))

Defaults for every plot: a given Look

When all your plots should be in one house style, say so once. A Look is a list of the same tweaks a plot takes, and every plot constructor (Plot.barcode, Plot.diagram, Plot.landscape, the 3-D ones, ...) starts from the given Look it finds. Nothing is imported: a given in your file, or in the block where you draw, is found. Without one, a plot is as its constructor makes it.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val d = Persistence(CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv"), maxDimension = 1)

given Look = Look.print + Text(TextRole.Title, size = 18) + Lines.grid(dash = Dash.Dotted)

Plot.barcode(d).save("barcode.svg") // in the look
Plot.diagram(d, palette = Palette.reference).save("diagram.svg") // a palette named in the call wins
(Plot.barcode(d) + Style.slides).save("slides.svg") // and so does a tweak added afterwards

Look.print and Look.clear are the palette and style of the two looks for a paper (see above), Look.none is nothing, and Look.named("print") takes a word. Add tweaks with + and looks with ++; the later one wins. A look serves figures and 3-D scenes alike: a tweak that a kind of plot cannot have (the tick labels of a scene) is left out for it, so the same look works for Plot.barcode and Plot.points3D. A given in a smaller scope replaces one in a larger, whole. To add to the look in scope instead, ask for it: given Look = summon[Look] + Text(TextRole.Title, size = 21) in an inner scope (a block, a method, a file that imports a shared look) is the look of the enclosing scope with one more tweak, or, where you have given none, the default (which changes nothing) with it. In the same scope as the look it builds on, it is an ambiguity error, as are two given Looks in one scope: nothing is merged silently. The default is found only when you have given no look.

From MATLAB and Java, which have no givens, a session has defaults of its own: TDA4j.setPlotDefaults takes the same settings as text (palette=print, style=print, title.size=18, ...), and every plot a result draws afterwards starts from them until TDA4j.clearPlotDefaults(). They belong to the thread that set them, which for MATLAB is the whole session.

import org.appliedtopology.tda4j.matlab.*;

TDA4j.setPlotDefaults({'palette=print', 'style=print', 'title.size=18'});
result = TDA4j.computeFromPoints(points, {'maxDimension', '1'});
result.plotBarcode().save('barcode.svg');      % in the print look
result.plotDiagram().withStyle('slides')       % what you chain on wins
TDA4j.clearPlotDefaults();

Comparing plots

Plots drawn side by side mean something only on the same scale. shared() gives every panel of a board the union of the panels' ranges, on both axes or on shared(y = false) the x axis only; a tweak added to a board with + changes every panel (Labels(title = ...) titles the board: the heading above the panels, and the title of the page it is saved as):

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val a = Persistence(CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv"), maxDimension = 1)
val b = Persistence(CSV.readPointCloud("_docs/tutorials/data/noisy-circle-b.csv"), maxDimension = 1)

val board = Plot.side(Plot.barcode(a).copy(title = "first"), Plot.barcode(b).copy(title = "second")).shared(y = false)
(board + Style(grid = false)).save("compare.svg")

Panels on a grid

Plot.side puts panels in a row. For more, Plot.layout(rows, cols) is an empty board on a grid of cells, and place(figure, row, col, rowSpan, colSpan) puts a panel with its top left corner in a cell and spanning as many rows and columns as it is given: a panel is as large as the cells it spans and the gaps between them, so its axes run across all of them. Cells count from 0. The drawing is width by height pixels (960 by 600), gap pixels between cells; the columns share the width equally unless widths gives their relative sizes (Seq(1.0, 3.0): the second column is three times as wide as the first), and so the rows with heights. The grid sets the size of every panel.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val d = Persistence(CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv"), maxDimension = 1)

val board = Plot.layout(2, 3, widths = Seq(2.0, 2.0, 1.0))
  .place(Plot.diagram(d), row = 0, col = 0, colSpan = 2, fill = true)
  .place(Plot.barcode(d), row = 0, col = 2)
  .place(Plot.barcode(d).withXScale(Transform.Sqrt), row = 1, col = 0, colSpan = 3)
  .tagged()
board.save("grid.svg")

A persistence diagram keeps equal units, so in a wide cell the data take a square and the rest is empty axis; fill = true (the same as withAspect(free = true) on that panel) lets it fill the cell, as above. A panel that would cover a cell another one covers, or that runs off the grid, is refused when it is placed, naming the panel in the way. tagged() letters the panels in the order they were placed.

On a grid, sharedColumns() puts the panels over the same columns on one x scale and sharedRows() the panels across the same rows on one y scale, each column and row its own (shared() still takes all panels together). A panel that spans columns is a kind of its own: it shares with no panel over one column. A panel alone in its group keeps its own axes as they are. The same two methods on a row of panels share nothing along columns (each is in its own) and everything along the row.

Reference lines and marks of your own

Mark.Rule draws a line across the plot at one value, and Mark.Diagonal(offset) the line y = x + offset: a threshold on a barcode, or the line above which a point of a diagram persists longer than offset. They take no part in choosing the visible range. Any other Mark can be added with + as well, in data coordinates:

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val diagram = Plot.diagram(d) +
  Mark.Diagonal(offset = 0.2, paint = Paint.Muted, dashed = true) +
  Mark.Text((0.1, 1.2), "persistence 0.2", anchor = Anchor.Start)
val barcode = Plot.barcode(d) + Mark.Rule.vertical(0.5)

From MATLAB and the command line

MATLAB and Java have no named or default arguments and cannot build a Palette or a Transform. Every figure therefore has its changes as methods that take only strings and numbers; each returns the changed figure, so they chain. A plot... method of a result returns a figure (a plot...3D method a scene), and a scene has the subset marked below.

Showing and saving

method does
view() shows the plot in the live viewer, a browser tab (see In a REPL)
save(path) writes an .svg (plain light colors) or an .html page (follows the reader's light or dark setting) and returns the absolute path
save(path, theme) the same with the theme 'light', 'dark' or 'auto'

Changes (a scene has those marked 3-D)

method changes
withTitle(text), withSubtitle(text) (3-D) the title and subtitle
withXLabel(text), withYLabel(text), withLegendTitle(text), withColorLabel(text) the axis labels, the legend heading, the color bar title
withCaption(text), withTag(text), withDescription(text) the line under the plot, the panel tag, the description a screen reader reads
withSize(width, height) (3-D) the size in pixels
withXScale(name), withYScale(name) 'linear', 'log', 'sqrt' or 'symlog'
withXRange(min, max), withYRange(min, max) the visible range of an axis
withXCrossesAt(y), withYCrossesAt(x) the x axis through y = value, the y axis through x = value
withAspect(ratio) the length of a y unit over an x unit
withPalette(name) (3-D) 'brand', 'reference', 'print', 'grayscale', 'okabe-ito' or 'clear'
withStyle(name) (3-D) 'default', 'slides', 'print' or 'clear'
withDegreeColor(k, color) (3-D), withDegreeLabel(k, label) the color ('#c2185b') and legend label of degree k
withTextScale(factor) (3-D), withMarkScale(factor) (3-D) a factor on the size of text, of marks and lines
withLegend(position) 'right', 'left', 'top', 'bottom', 'upper-left', 'upper-right', 'lower-left', 'lower-right' or 'none'
withLegendBox(color), withLegendColumns(n) a box round the legend, filled with color and framed; the entries in n columns (withSetting('legend-box.padding=10') and its siblings reach the rest)
withoutGrid() removes the gridlines
withTransparentBackground() (3-D) draws no background, on a page as well as in a saved file
withOpaqueBackground() (3-D) draws the background in a saved .svg too, where there is none unless asked
withLocale(tag) writes numbers as a locale does ('de', 'sv', ...)
withSetting(spec) (3-D) any change of an element, as 'element.property=value' (see finer control)
withCamera(azimuth, elevation, zoom) (3-D only) the view of a 3-D scene

A word that is not one of those listed, or a change a plot cannot have, throws an IllegalArgumentException that says what to write instead.

Boards too (see Comparing plots and Panels on a grid). MATLAB cannot build a Scala Seq, so the boards are made in TDA4j, and the board has the methods that take plain arguments:

call meaning
TDA4j.side(a, b), TDA4j.side(a, b, c), TDA4j.side(array) the figures in one row, as one plot (array is a Java array of figures)
TDA4j.layout(rows, cols), TDA4j.layout(rows, cols, width, height) an empty board on a grid of cells
TDA4j.layout(rows, cols, width, height, gap, widths, heights) the same with the gap between cells and the relative sizes of columns and rows (an empty array for equal ones)
board.place(fig, row, col), board.place(fig, row, col, rowSpan, colSpan) a panel in a cell, or spanning cells; cells count from 0
board.place(fig, row, col, rowSpan, colSpan, fill) with fill true, a diagram fills a wide cell instead of keeping equal units
board.tagged(), board.tagged(format, sequence) letters the panels (a), (b), ...
board.shared(), board.sharedColumns(), board.sharedRows() panels on one scale, by column, by row
board.withTitle(text), withPalette(name), withStyle(name), withTextScale(factor), withSetting(spec) the board's heading, and the change in every panel
board.save(path), board.save(path, theme) writes an .svg file or an .html page
grid = TDA4j.layout(2, 2, 960, 600).place(result.plotDiagram(), 0, 0, 1, 2, true).place(result.plotBarcode(), 1, 0, 1, 2);
grid.tagged().withTitle('A noisy circle').save('grid.svg');

The command line draws one plot per call; it has no board.

import scala.language.experimental.modularity
import org.appliedtopology.tda4j.*
import org.appliedtopology.tda4j.plot.*

val points = CSV.readPointCloud("_docs/tutorials/data/noisy-circle.csv")
val d = Persistence(points, maxDimension = 1)

val diagram = Plot.diagram(d).withLabels(title = "A noisy circle", x = "birth", y = "death").withSize(800, 600)
diagram.save("diagram.svg")
Plot.barcode(d).withXScale(Transform.Sqrt).withStyle(Style(textScale = 1.3)).save("barcode.svg")
import org.appliedtopology.tda4j.matlab.*;

points = readmatrix('_docs/tutorials/data/noisy-circle.csv');
result = TDA4j.computeFromPoints(points, {'maxDimension', '1'});

result.plotDiagram().withTitle('A noisy circle').withXLabel('birth').withYLabel('death').withSize(800, 600).save('diagram.svg');
result.plotBarcode().withXScale('sqrt').withTextScale(1.3).save('barcode.svg');
import numpy as np
import tda4j

points = np.loadtxt("_docs/tutorials/data/noisy-circle.csv", delimiter=",")
result = tda4j.persistence(points, max_dimension=1)

result.plot_diagram().with_title("A noisy circle").with_x_label("birth").with_y_label("death").with_size(800, 600).save("diagram.svg")
result.plot_barcode().with_x_scale("sqrt").with_text_scale(1.3).save("barcode.svg")

The command line has a flag for the same changes of a --plot: --title, --x-label, --y-label, --caption, --tag, --description, --layout and --tagged (for a list of kinds on a board), --look (default, print or clear: the palette and style together, which the flags after it override), --width, --height, --palette (brand, reference, print, grayscale, okabe-ito or clear), --style (default, slides, print or clear), --theme (light, dark or auto), --text-scale (applied to the --style), --set (repeated, element.property=value), --x-scale and --y-scale (linear, log, sqrt or symlog). A word that is not one, a size out of range and a flag a plot cannot use (an x scale for a 3-D scene) are errors, reported before anything is computed:

java -jar tda4j-assembly.jar --plot diagram --title "A noisy circle" --x-scale sqrt --width 800 --output diagram.svg circle.json

Every plot is an immutable value, and Figure, Mark and Scene are there to build plots of your own: copy(...) changes any part directly, Tweak(f) makes a tweak of your own from a function on figures, and over draws one figure on another.