Bivariate analysis
Compare two numeric variables and inspect their relationship.
Plotly · Function
px.scatter creates an interactive two-dimensional scatter plot, placing each observation as a marker at its x and y values. Data can come from dataframe columns or array-like sequences, with optional visual encodings such as color, size, and trendlines.
px.scatter builds an interactive two-dimensional scatter figure from array-like values or dataframe columns. Map columns to the x and y axes, then optionally encode additional data with parameters such as color, size, facets, or trendlines before displaying or updating the returned figure.
plotly.express.scatter(data_frame=None, x=None, y=None, color=None, symbol=None, size=None, hover_name=None, hover_data=None, custom_data=None, text=None, facet_row=None, facet_col=None, facet_col_wrap=0, facet_row_spacing=None, facet_col_spacing=None, error_x=None, error_x_minus=None, error_y=None, error_y_minus=None, animation_frame=None, animation_group=None, category_orders=None, labels=None, orientation=None, color_discrete_sequence=None, color_discrete_map=None, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, symbol_sequence=None, symbol_map=None, opacity=None, size_max=None, marginal_x=None, marginal_y=None, trendline=None, trendline_options=None, trendline_color_override=None, trendline_scope='trace', log_x=False, log_y=False, range_x=None, range_y=None, render_mode='auto', title=None, subtitle=None, template=None, width=None, height=None)| Name | Type | Description |
|---|---|---|
data_frame | DataFrame or array-like | Dataframe or array-like data source used by the Plotly Express function. |
x | str or array-like | Column name or array-like values mapped to the horizontal axis. |
y | str or array-like | Column name or array-like values mapped to the vertical axis. |
color | str or array-like | Column or values used to assign marker colors. |
size | str or array-like | Column or values used to control marker size. |
trendline | str | Trendline method to add to the scatter plot. |
A Plotly figure object.
import plotly.express as px
fig = px.scatter(
px.data.iris(),
x="sepal_width",
y="sepal_length",
color="species",
)
fig.show()Creates and displays an interactive scatter plot from Plotly’s built-in Iris dataframe, coloring points by species.
Compare two numeric variables and inspect their relationship.
Distinguish categories through marker color or symbol.
Show a third numeric measure through marker area.
Explore distributions alongside the x-y relationship.
px.scatter create, and how are points positioned?The function returns a complete Plotly figure, so it can be displayed immediately or further customized. Its x and y inputs determine each marker’s position, while other arguments can encode additional dimensions.
Follow-up: How would you force SVG rendering for a larger chart? Pass render_mode="svg" so the underlying trace uses the regular scatter type instead of WebGL.
px.scatter?Pass a dataframe as the first argument and provide column names such as x="sepal_width" and y="sepal_length". Plotly Express also accepts array-like x and y values directly.
Follow-up: What data-shape flexibility is available? The function supports long-form data and, as a 2D-Cartesian Plotly Express function, wide-form and mixed-form data.
Use color to distinguish groups, size to vary marker size, and options such as marginal plots or trendlines for additional analysis. These mappings are specified while constructing the figure.
Follow-up: How can the resulting chart be refined after construction? Update traces or layout with figure methods such as fig.update_traces or fig.update.
px.linepx.scatter_3dpx.scatter_matrixgo.Scatter