Scatter Series

The Scatter Series is a type of plot where data points are plotted individually. A minimal example that records a 2D uniform distribution is provided below:

import { Component, type Entity, Analysis, ScatterSeries, Random } from "prototwin";

export class Graph extends Component {
    #scatterSeries: ScatterSeries;

    constructor(entity: Entity) {
        super(entity);
        this.#scatterSeries = new ScatterSeries("Scatter"); // Create the series.
    }

    public override initialize() {
        // Create the plot and add the series to it.
        const scatterPlot = Analysis.plots.add("uniform", "2D Uniform Distribution");
        scatterPlot!.add(this.#scatterSeries);
    }

    public override update(dt: number) {
        // Add a data point to the series every timestep.
        const x = Random.global.nextNumber();
        const y = Random.global.nextNumber();
        this.#scatterSeries.add(x, y);
    }
}
Scatter Series