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

Plotly · Function

px.scatter

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.

How it works

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.

Syntax

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)

Parameters

NameTypeDescription
data_frameDataFrame or array-likeDataframe or array-like data source used by the Plotly Express function.
xstr or array-likeColumn name or array-like values mapped to the horizontal axis.
ystr or array-likeColumn name or array-like values mapped to the vertical axis.
colorstr or array-likeColumn or values used to assign marker colors.
sizestr or array-likeColumn or values used to control marker size.
trendlinestrTrendline method to add to the scatter plot.

Returns

A Plotly figure object.

Key points

  • Each observation is drawn as a marker, with its position determined by the selected x and y values.
  • For dataframe input, x and y commonly refer to column names that define the two plotted coordinates.
  • A dataframe is optional: independent array-like sequences can provide the x and y coordinates.
  • When using tabular data, place the dataframe in the first positional argument.
  • After supplying a dataframe, use strings naming its columns for mappings such as x, y, color, and size.
  • A scatter figure can include a built-in trendline, and its fitted model output can be accessed.

Example: Scatter plot from a dataframe

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.

When to use it

Bivariate analysis

Compare two numeric variables and inspect their relationship.

Group comparison

Distinguish categories through marker color or symbol.

Multivariate encoding

Show a third numeric measure through marker area.

Marginal diagnostics

Explore distributions alongside the x-y relationship.

Interview questions

QWhat does 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.

QHow do you supply data to 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.

QHow can a scatter plot encode more than x and y?

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.line
  • px.scatter_3d
  • px.scatter_matrix
  • go.Scatter

Source: Scatter Plots in Python. Checked 2026-10-15.