Trend over time
A time-indexed data frame contains one metric and a date column.
Plotly · Function
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.
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.
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)| Name | Type | Description |
|---|---|---|
data_frame | DataFrame or array-like | Data frame containing the columns or arrays used to construct the chart. |
x | str or array-like | Column name or array-like values for the horizontal coordinate. |
y | str or array-like | Column name or array-like values for the vertical coordinate. |
color | str or array-like | Column used to assign separate colors to line groups. |
markers | bool | Whether to display markers on the lines. |
A plotly.graph_objects.Figure containing the interactive line chart.
markers=True to add visible markers at the observations.px.line supports the same broad 2D Cartesian data-shape family as several other Plotly Express functions.markers=True when individual observations should be visible.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.
A time-indexed data frame contains one metric and a date column.
One categorical field identifies several entities sharing the same x-axis.
Coordinates and measurements are already available as Python sequences.
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.
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.
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.expresspx.scatterpx.areapx.barpx.line_geopx.line_polar