3D path visualization
Plot a single trajectory through three measured dimensions.
Plotly · Function
px.line_3d creates an interactive 3D line chart by connecting points defined by x, y, and z data. Use grouping options such as color to render multiple trajectories.
px.line_3d builds a Plotly figure whose vertices use three data dimensions supplied through x, y, and z. Optional Plotly Express arguments can divide the data into groups, such as using color to create separate colored lines.
plotly.express.line_3d(data_frame=None, x=None, y=None, z=None, color=None, ...)| Name | Type | Description |
|---|---|---|
data_frame | data frame | Data frame or compatible data source containing the plotted values. |
x | str or array-like | Column or array supplying x coordinates. |
y | str or array-like | Column or array supplying y coordinates. |
z | str or array-like | Column or array supplying z coordinates. |
color | str or array-like | Column used to assign observations to colored groups. |
A Plotly Figure object representing the 3D line chart.
color to split observations into separate colored trajectories, such as one line per country.scatter3d reference.import plotly.express as px
df = px.data.gapminder().query("country == 'Brazil'")
fig = px.line_3d(df, x="gdpPercap", y="pop", z="year")
fig.show()Creates and displays a 3D line chart from selected Gapminder rows.
Plot a single trajectory through three measured dimensions.
Compare several entities across the same three coordinates.
Explore multivariate movement interactively.
px.line_3d create, and what do x, y, and z represent?It creates a 3D line chart from a data frame or compatible column-like inputs. The x, y, and z arguments determine the three coordinates of each line vertex.
Follow-up: How can multiple trajectories be distinguished? Use a grouping argument such as color to generate separate traces and assign distinct colors.
Pass a data frame as the first argument, then provide its column names as strings for x, y, and z. Plotly Express uses those columns to construct the 3D coordinates.
Follow-up: How would you encode a categorical series? Pass its column to color, for example color='country', to separate and color the trajectories.
Use color when the data contains multiple trajectories that should be visually separated. The documentation demonstrates filtering Gapminder data and setting color='country' to produce country-specific lines.
Follow-up: What is the next place to inspect for trace-level styling? Consult the scatter3d reference for chart attributes such as marker and line options.
plotly.expressscatter3dpx.data.gapminderpx.line