Trend and relationship plots
Plot measured or modeled values against an x-axis with points, connecting lines, or both.
Plotly · Module
Adds a scatter trace to a Plotly figure, with support for x/y data, rendering modes, labels, styling, and subplot placement. It returns the updated figure for continued construction or display.
fig.add_scatter creates a Scatter trace from keyword arguments and appends it to the figure. Trace properties such as coordinates, rendering mode, labels, styling, and subplot placement can be supplied directly; the method returns the figure so calls can be chained.
fig.add_scatter(row=None, col=None, secondary_y=None, **kwargs)| Name | Type | Description |
|---|---|---|
kwargs | dict | Scatter trace properties, including data, display mode, labels, styling, and axis-related settings. |
row | int | Subplot row in which to place the trace. |
col | int | Subplot column in which to place the trace. |
secondary_y | bool | Whether the trace uses the subplot's secondary y-axis when supported by the layout. |
The updated Figure object.
text attribute when each point needs associated annotation content.row and col coordinates; the target cell must exist in the figure's subplot layout.import plotly.graph_objects as go
fig = go.Figure()
fig.add_scatter(
x=[1, 2, 3],
y=[2, 5, 3],
mode="lines+markers",
name="Series A",
)
fig.show()Creates a figure, adds a scatter trace with x/y data and combined lines and markers, then displays the interactive chart.
Plot measured or modeled values against an x-axis with points, connecting lines, or both.
Build a chart incrementally by appending multiple independent scatter series.
Place traces into cells of a figure created with Plotly's subplot utilities.
Create filled regions or stacked area visualizations from scatter traces.
fig.add_scatter do?fig.add_scatter adds a go.Scatter trace to an existing go.Figure. It is convenient when constructing a figure incrementally because scatter attributes can be passed as keyword arguments.
Follow-up: How would you add two independent series? Call add_scatter twice, supplying distinct x/y data and names; Plotly renders each call as its own trace.
The mode attribute controls whether the scatter trace displays markers, lines, text, or combinations of them. For example, mode="lines+markers" renders both connecting lines and points.
Follow-up: How can an area be filled? Use a scatter trace's fill setting, such as fill="tozeroy" or fill="tonexty", and choose mode="none" when markers and lines are unnecessary.
A scatter trace can be positioned in a subplot by passing row and col to the add method. This places the trace in the selected subplot cell rather than the default location.
Follow-up: How can a trace use a secondary y-axis? In a subplot configured with secondary axes, pass the relevant secondary-axis option when adding the trace.
go.Scatterfig.add_tracefig.add_tracesfig.update_traces