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

Plotly · Function

px.line_3d

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.

How it works

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.

Syntax

plotly.express.line_3d(data_frame=None, x=None, y=None, z=None, color=None, ...)

Parameters

NameTypeDescription
data_framedata frameData frame or compatible data source containing the plotted values.
xstr or array-likeColumn or array supplying x coordinates.
ystr or array-likeColumn or array supplying y coordinates.
zstr or array-likeColumn or array supplying z coordinates.
colorstr or array-likeColumn used to assign observations to colored groups.

Returns

A Plotly Figure object representing the 3D line chart.

Key points

  • The function accepts a data frame and maps three named columns to the x, y, and z coordinates.
  • Use color to split observations into separate colored trajectories, such as one line per country.
  • The 3D line plot documentation directs readers to the function reference for the complete API.
  • Trace-level marker and line styling is documented in the related scatter3d reference.

Example: Basic 3D line chart

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.

When to use it

3D path visualization

Plot a single trajectory through three measured dimensions.

Grouped trajectories

Compare several entities across the same three coordinates.

Interactive 3D exploration

Explore multivariate movement interactively.

Interview questions

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

QHow do you map data-frame columns to a 3D line plot?

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.

QHow can you show multiple 3D lines with different colors?

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.express
  • scatter3d
  • px.data.gapminder
  • px.line

Source: 3D Line Plots in Python. Checked 2026-10-15.