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

Plotly · Function

px.scatter_3d

Creates an interactive three-dimensional scatter plot, with each data-frame row represented as a point. Map columns or arrays to x, y, and z, then optionally encode additional variables through color, size, symbol, and other Plotly Express options.

How it works

px.scatter_3d maps rows from an optional data frame into points in three-dimensional space. The x, y, and z arguments select the three coordinates, while optional encodings such as color, size, symbol, and animation settings control additional visual dimensions and interaction.

Syntax

plotly.express.scatter_3d(data_frame=None, x=None, y=None, z=None, color=None, symbol=None, size=None, text=None, hover_name=None, hover_data=None, custom_data=None, error_x=None, error_y=None, error_z=None, animation_frame=None, animation_group=None, category_orders=None, labels=None, size_max=None, color_discrete_sequence=None, color_discrete_map=None, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, opacity=None, log_x=False, log_y=False, log_z=False, range_x=None, range_y=None, range_z=None, title=None, template=None, width=None, height=None)

Parameters

NameTypeDescription
data_frameDataFrame or array-likeOptional data frame supplying the plotted data.
xstr, int, Series, array-like, or NoneColumn or array used for the x coordinate.
ystr, int, Series, array-like, or NoneColumn or array used for the y coordinate.
zstr, int, Series, array-like, or NoneColumn or array used for the z coordinate.
colorstr, int, Series, array-like, or NoneOptional grouping or continuous color encoding.
sizestr, int, Series, array-like, or NoneOptional marker-size encoding.
...various keyword argumentsAdditional Plotly Express options such as symbol, hover data, animation, labels, and layout settings.

Returns

A Plotly figure representing the 3D scatter plot.

Key points

  • Each row of the supplied data frame becomes one plotted point.
  • The function is the three-dimensional counterpart of Plotly Express's 2D scatter chart.
  • Many visual properties can be configured directly through the function's keyword arguments.
  • After construction, refine the chart by updating its traces or layout.

Example: Basic 3D scatter plot

import plotly.express as px

fig = px.scatter_3d(
    px.data.iris(),
    x="sepal_length",
    y="sepal_width",
    z="petal_width",
    color="species",
)
fig.show()

Creates an interactive 3D scatter plot from Plotly Express's built-in iris dataset.

When to use it

Inspect 3D relationships

Exploratory analysis of three numeric dimensions.

Encode an extra variable

Add a categorical or numeric variable to point appearance.

Animate changing data

Explore observations across a time or category sequence.

Interview questions

QWhat does px.scatter_3d create, and how are coordinates assigned?

It is a Plotly Express function that creates a 3D scatter plot, representing each data-frame row as a point. The three spatial coordinates are supplied through x, y, and z.

Follow-up: How would you represent a fourth variable? Use an encoding such as color, size, symbol, or an animation-related parameter rather than another spatial axis.

QHow would you create a colored 3D scatter plot from tabular data?

Pass a data frame as the first argument and identify its columns with x, y, and z. A categorical column can be mapped with color, as in the documented iris example.

Follow-up: How can the resulting chart be customized after creation? Update the returned figure's traces or layout with methods such as fig.update.

QHow can the figure returned by px.scatter_3d be customized?

The function returns a Plotly figure object, which can be displayed with fig.show(). Styling can be supplied through supported function parameters or applied afterward through figure and trace updates.

Follow-up: When would you use the lower-level API? Use a Scatter3d graph-object trace when direct control over trace attributes is required.

  • scatter
  • scatter_3d
  • scatter_matrix
  • Scatter3d

Source: plotly.express : high-level interface for data visualization. Checked 2026-10-15.