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

Plotly · Class

go.Scatter

go.Scatter is Plotly’s generic graph_objects trace for two-dimensional scatter visualizations. Its mode controls whether data appears as markers, lines, or both.

How it works

go.Scatter creates a generic two-dimensional scatter trace for plotly.graph_objects. Set mode to choose points, lines, or both, then place the trace in a Figure and display the result.

Syntax

go.Scatter(x=None, y=None, mode=None, **kwargs)

Key points

  • The class belongs to the plotly.graph_objects module and is instantiated as go.Scatter after importing that module.
  • One trace type supports both point-based and line-based visualizations.
  • The mode attribute controls whether the trace displays markers, lines, or a combination.
  • A scatter trace can be passed directly as the Figure data when constructing a chart.
  • Choose mode according to whether the chart should show markers, lines, or both.

Common mistakes

  • The trace's visual form depends on mode; choose its value explicitly when you need markers, lines, or both.

Example: Markers and lines with go.Scatter

import plotly.graph_objects as go

fig = go.Figure(go.Scatter(
    x=[1, 2, 3],
    y=[2, 1, 4],
    mode="markers+lines",
    name="Measurements"
))
fig.show()

Creates an interactive Plotly figure containing one scatter trace with both points and connecting lines.

When to use it

Point plots

Show individual observations as points in an interactive chart.

Line plots

Connect ordered measurements to reveal a trend.

Marker-and-line charts

Combine observations and their connecting path in one trace.

Custom graph_objects figures

Use a lower-level trace when Plotly Express is not a suitable starting point.

Interview questions

QWhat is go.Scatter used for?

go.Scatter is a generic graph_objects class for two-dimensional scatter traces. It can represent either points or lines, and the mode value determines which rendering is used.

Follow-up: How would you render both representations? Set mode to the combined markers-and-lines option, such as "markers+lines".

QHow do you display a go.Scatter trace?

Create the trace with x and y data, pass it to go.Figure, and call show on the figure. The documented pattern is a Figure containing a go.Scatter trace.

Follow-up: How can the trace be added after figure construction? Use the Figure add-trace method with a go.Scatter instance.

QHow does go.Scatter relate to Plotly Express?

Plotly Express provides separate scatter and line functions, while go.Scatter is the lower-level generic option that supports both kinds of plot through mode.

Follow-up: When should you consider the graph_objects class? Use it when Plotly Express is not a suitable starting point or when direct trace control is needed.

  • plotly.graph_objects.Figure
  • plotly.express.scatter
  • plotly.express.line
  • go.Scatter3d

Source: Scatter Plots in Python | Plotly. Checked 2026-10-15.