Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Function

px.scatter_matrix

px.scatter_matrix builds an interactive scatterplot matrix for multiple numerical variables. Choose included columns with dimensions and distinguish observations with color.

How it works

px.scatter_matrix creates a Plotly scatterplot-matrix figure from tabular data. Each matrix cell compares one selected variable with another; use dimensions to choose columns, color to encode a dataframe column, and update_traces for further figure-level refinement.

Syntax

px.scatter_matrix(data_frame=None, dimensions=None, color=None, ...)

Parameters

NameTypeDescription
data_frameDataFrame or array-likeDataframe or array-like input containing the variables to compare.
dimensionslist-likeNames or positions of columns to include as matrix dimensions.
colorstr or array-likeDataframe column used to assign observation colors.

Returns

A Plotly figure containing a scatterplot matrix.

Key points

  • The visualization compares multiple equal-length numerical variables in one matrix.
  • Every cell represents a pairwise scatter plot, so row and column positions determine the variables being compared.
  • Use this Plotly Express function when the source data is organized in dataframe columns.
  • The dimensions argument narrows the matrix to chosen columns, while color can encode a dataframe field.

Common mistakes

  • If dimensions is omitted, Plotly Express includes every column rather than only numeric columns you intended to inspect.
  • Some visual adjustments are made after construction with fig.update_traces, such as hiding the diagonal cells.

Example: Colored scatterplot matrix

import plotly.express as px

df = px.data.iris()
fig = px.scatter_matrix(
    df,
    dimensions=["sepal_length", "sepal_width", "petal_length", "petal_width"],
    color="species",
)
fig.show()

Builds a scatterplot matrix from selected Iris measurements and colors observations by species.

When to use it

Multivariate exploratory analysis

Explore pairwise relationships among several numerical features.

Category-based comparison

Compare groups across every pair of selected measurements.

Feature screening

Inspect high-dimensional data before applying dimensionality reduction.

Interview questions

QWhat does px.scatter_matrix create?

It produces a scatterplot matrix: for n variables, each cell compares one variable against another, and the diagonal represents each variable paired with itself. The function returns a Plotly figure that can be displayed with fig.show().

Follow-up: How would you reduce the matrix size? Pass only the desired column names through dimensions.

QHow do you select variables and encode categories?

Use dimensions to specify the dataframe columns represented in the matrix. Add color with a dataframe column name to distinguish observations by category, as in color="species".

Follow-up: How could you remove the diagonal plots after creating the figure? Call fig.update_traces(diagonal_visible=False).

QWhere can you apply further customization?

The function accepts the dataframe as its first argument and can be customized through its parameters. Additional trace-level tuning is available through fig.update_traces, while chart attribute options are documented for the splom trace.

Follow-up: What underlying Plotly trace type is associated with this chart? It is the splom trace, whose attributes provide further chart-level control.

  • px.scatter
  • px.parallel_coordinates
  • px.parallel_categories
  • fig.update_traces
  • splom

Source: Scatterplot matrix in Python - Plotly. Checked 2026-10-15.