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

Plotly · Function

px.line

px.line creates an interactive 2D line chart by connecting data points into polyline marks. It accepts direct sequences or data-frame columns and supports encodings such as color and visible markers.

How it works

px.line builds a Plotly figure whose points are connected in order by polyline marks. It accepts sequences directly or columns from a data frame, and can encode additional fields such as color to produce separate lines; the returned figure can then be displayed or customized.

Syntax

plotly.express.line(data_frame=None, x=None, y=None, line_group=None, color=None, line_dash=None, symbol=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, line_dash_sequence=None, line_dash_map=None, symbol_sequence=None, symbol_map=None, markers=None, log_x=False, log_y=False, range_x=None, range_y=None, line_shape=None, render_mode='auto', title=None, template=None, width=None, height=None)

Parameters

NameTypeDescription
data_frameDataFrame or array-likeData frame containing the columns or arrays used to construct the chart.
xstr or array-likeColumn name or array-like values for the horizontal coordinate.
ystr or array-likeColumn name or array-like values for the vertical coordinate.
colorstr or array-likeColumn used to assign separate colors to line groups.
markersboolWhether to display markers on the lines.

Returns

A plotly.graph_objects.Figure containing the interactive line chart.

Key points

  • The function models every observation as a vertex in a two-dimensional polyline.
  • When using tabular data, the x and y columns determine each point's coordinates.
  • Points are connected into a 2D polyline mark rather than rendered as isolated observations.
  • Set markers=True to add visible markers at the observations.
  • Plotly Express functions conventionally begin with an optional data-frame argument.
  • px.line supports the same broad 2D Cartesian data-shape family as several other Plotly Express functions.

Common mistakes

  • Input points become vertices of the polyline, so the order of the supplied data determines how the line is connected.
  • Markers are not shown by default; pass markers=True when individual observations should be visible.

Example: Basic interactive line chart

import plotly.express as px

fig = px.line(
    x=["Jan", "Feb", "Mar"],
    y=[10, 14, 12],
    markers=True,
    labels={"x": "Month", "y": "Value"},
    title="Monthly values",
)
fig.show()

Creates and displays an interactive line chart from x and y sequences, with point markers and axis labels.

When to use it

Trend over time

A time-indexed data frame contains one metric and a date column.

Compare multiple series

One categorical field identifies several entities sharing the same x-axis.

Quick exploratory plot

Coordinates and measurements are already available as Python sequences.

Interview questions

QWhat does px.line represent visually?

It creates an interactive Plotly figure in which each data point is a vertex and the vertices are connected by a polyline. The x and y values determine the locations of those vertices.

Follow-up: How would you show the individual observations? Pass markers=True, which adds markers to the lines.

QHow can px.line receive data?

Provide sequences such as x=[...] and y=[...], or provide a data frame and name its columns with x and y. The function also supports long-form and, for this 2D Cartesian function, wide-form or mixed-form data.

Follow-up: What is the first argument of Plotly Express functions? It is data_frame, although direct x and y sequences can also be supplied.

QHow do you create multiple lines from one data frame?

A line chart with multiple series can be made by mapping a data-frame field to color, for example color="country". This produces separate colored lines for the field's categories.

Follow-up: How can points be distinguished beyond color? Use additional supported encodings such as symbol where appropriate, or enable markers for visible points.

  • plotly.express
  • px.scatter
  • px.area
  • px.bar
  • px.line_geo
  • px.line_polar

Source: Line Charts in Python - Plotly. Checked 2026-10-15.