Multivariate exploratory analysis
Explore pairwise relationships among several numerical features.
Plotly · Function
px.scatter_matrix builds an interactive scatterplot matrix for multiple numerical variables. Choose included columns with dimensions and distinguish observations with color.
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.
px.scatter_matrix(data_frame=None, dimensions=None, color=None, ...)| Name | Type | Description |
|---|---|---|
data_frame | DataFrame or array-like | Dataframe or array-like input containing the variables to compare. |
dimensions | list-like | Names or positions of columns to include as matrix dimensions. |
color | str or array-like | Dataframe column used to assign observation colors. |
A Plotly figure containing a 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.
Explore pairwise relationships among several numerical features.
Compare groups across every pair of selected measurements.
Inspect high-dimensional data before applying dimensionality reduction.
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.
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).
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.scatterpx.parallel_coordinatespx.parallel_categoriesfig.update_tracessplom