Skip to main content

Scatter plot

Scatter plot visualizes values as points in a 2D plane. It is especially useful when you have at least two dimensions and want to see patterns, clusters, or correlations between them.

You select Scatter plot in SA Studio by choosing Scatter plot from the visualization selector.

//plot: Scatter plot
select [cos(x), sin(x)]
from Number x
where x in heartbeat(0.01)*10/(2*PI())
limit 500;

This example streams points on a unit circle by plotting cos(x) on the X-axis and sin(x) on the Y-axis.

Interaction

  • Zoom: click and drag on the plot to zoom in.
  • Reset zoom: double-click anywhere in the plot.

Supported data formats

Scatter plot supports the same incremental and batch data categories as the other visualizations.

Incremental data types (streaming, with history):

  • Number
  • Vector of Number
  • Record
  • Timeval of Number
  • Timeval of Vector of Number
  • Timeval of Record

Batch data types (full dataset rendered at once):

  • Vector of Vector of Number
  • Vector of Record
  • Timeval of Vector of Vector of Number
  • Timeval of Vector of Record
  • Vector of Timeval of Vector of Number
  • Vector of Timeval of Record

For batch types, all points are rendered in one go rather than as a scrolling history.

Changing axes, size, and color

Scatter plot can also show different sizes (and colors) for each point, and you can configure which values go on each axis.

The default mapping when the input is a Record is:

  • X-axis: the first label in the record
  • Y-axis: the second label in the record
  • Size: the third label in the record
  • Color: off by default (can be enabled in the settings dialog)

Example with labeled fields:

//plot: Scatter plot
select { "cos(x)": cos(x),
"sin(x)": sin(x),
"mod(x,2)": mod(round(x),2),
"cos(x)*sin(x)": cos(x)*sin(x)
}
from Number x
where x in heartbeat(0.01)*100
limit 500;

Here, by default:

  • cos(x) is used as X
  • sin(x) is used as Y
  • mod(x,2) controls point size
  • cos(x)*sin(x) is available to use as color

To choose which label to use for color, open the settings dialog (cogwheel icon) in the plot and pick a label for the color axis.

Plotting batches

When Scatter plot receives a batch data type, it renders all points in the batch directly:

//plot: Scatter plot
select vector of { "cos(x)": cos(x),
"sin(x)": sin(x),
"mod(x,2)": mod(round(x),2),
"cos(x)*sin(x)": cos(x)*sin(x)
}
from Number x
where x in heartbeat(0.01)*100
limit 100;

In this case, the result is a Vector of Record, so the scatter plot shows all points from the batch at once.


Scatter plot in Multi plot

Scatter plot can also be used through Multi plot. This gives you more control over axes, labels, size, color, memory, layout, and how streams are routed into different plots.

To use Scatter plot in a Multi plot definition, you specify a JSON record with sa_plot or sa_plots and include "Scatter plot" as one of the plot types.

Single Scatter plot via Multi plot

You can use Multi plot even when you only want one Scatter plot. This is useful when you want to configure scatter-specific parameters directly in the JSON.

The generic format for a single plot in Multi plot is:

{
"sa_plot": "Scatter plot",
"labels": ["x", "y"],
"size_axis": "none",
"color_axis": "none",
"memory": 500,
"batch": 0
}
  • sa_plot: set to "Scatter plot" to use the Scatter visualization.
  • labels: optional list of labels to use for the data.
  • memory: how many points to keep when streaming (incremental types).
  • batch: if 1, treat the data as a batch and render all at the end; otherwise plot incrementally.
  • size_axis: which label, index, or "none" to use for point size.
  • color_axis: which label, index, or "none" to use for point color.

Example: Scatter plot with explicit size and color axes

//plot: Multi plot
{
"sa_plot": "Scatter plot",
"labels": ["x", "y", "size", "color"],
"size_axis": "size",
"color_axis": "color",
"memory": 500
};
select [cos(x), sin(x), mod(round(x),2), cos(x)*sin(x)]
from Number x
where x in heartbeat(0.01)*100
limit 500;

Here we:

  • Produce a 4D vector [x, y, size, color].
  • Use labels to name each dimension.
  • Tell Multi plot to use "size" and "color" for size and color axes of the Scatter plot.

Using vector indices for size and color

If your query returns a vector instead of a labeled record, you can still configure which index controls size and color by using numeric values in size_axis and color_axis.

//plot: Multi plot
{
"sa_plot": "Scatter plot",
"size_axis": 2,
"color_axis": 3
};
select [cos(x), sin(x), mod(round(x),2), cos(x)*sin(x)]
from Number x
where x in heartbeat(0.01)*100
limit 500;

Here:

  • Index 0 (first element) is used as X.
  • Index 1 (second element) is used as Y.
  • Index 2 is used for point size.
  • Index 3 is used for color.

Multiple plots including Scatter plot

Multi plot can show multiple plots at once. The top-level JSON then uses "sa_plots" (plural) instead of "sa_plot".

The generic format is:

{
"sa_plots": [
"Line plot",
{ "sa_plot": "Scatter plot", "memory": 500 },
"Bar plot"
],
"labels": ["x", "y"]
}
  • sa_plots: list of plots to create. Each element can be a string (e.g., "Scatter plot") or a full sa_plot record.
  • Attributes outside sa_plots (like labels) apply to all plots.

Example OSQL using a Scatter plot together with other plots:

//plot: Multi plot
{
"sa_plots": [
"Line plot",
{ "sa_plot": "Scatter plot", "memory": 500 }
],
"labels": ["x", "y"]
};
select [cos(x), sin(x)]
from Number x
where x in heartbeat(0.01)*10/(2*PI())
limit 500;

In this example:

  • Both the Line plot and the Scatter plot receive the same data.
  • labels applies to both plots, naming the two dimensions.

Layout and grid

When using Multi plot, you can control the layout of the plots using the grid attribute inside each sa_plot record. This works for Scatter plot as well.

{
"sa_plots": [
{ "sa_plot": "Scatter plot", "grid": { "w": 6, "h": 6, "x": 0 } },
{ "sa_plot": "Scatter plot", "grid": { "w": 6, "h": 6, "x": 6 } }
],
"labels": ["x", "y"]
}
  • grid.w and grid.h: width and height of the plot in grid units.
  • grid.x: horizontal position in the grid.

This lets you place multiple Scatter plots (or mixed plot types) side by side or in more complex layouts.

Summary

  • Use Scatter plot directly for simple 2D point visualizations and basic size/color configuration via the settings dialog.
  • Use Scatter plot in Multi plot when you need full control over labels, size and color axes, memory vs. batch behavior, and layout, or when combining Scatter plots with other plot types.