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

Plotly · Class

go.Figure

go.Figure constructs a Plotly graph-object figure from optional traces and layout settings. Start empty for incremental construction or provide data and layout immediately.

How it works

Constructs a Plotly figure from optional data and layout inputs. The data can contain graph-object traces, while the layout configures chart-wide properties; an empty figure can also be created and populated later with methods such as add_trace and update_layout.

Syntax

plotly.graph_objects.Figure(data=None, layout=None, frames=None, skip_invalid=False, **kwargs)

Parameters

NameTypeDescription
dataarray-likePlotly trace or traces used as the figure's plotted data.
layoutplotly.graph_objects.LayoutChart-wide configuration, including axes and presentation properties.

Returns

A plotly.graph_objects.Figure instance.

Key points

  • Call go.Figure() with no arguments to obtain an empty figure, then add chart content afterward.
  • A figure can be initialized directly from a list containing graph-object traces.
  • After construction, update_layout can change axis configuration such as a date range.
  • An empty figure can be populated incrementally by adding traces with add_trace.

Common mistakes

  • Plotly Express functions cannot be used to create an empty figure; use go.Figure() when constructing the chart incrementally.

Example: Create and display a figure

import plotly.graph_objects as go

fig = go.Figure(
    data=[go.Scatter(x=[1, 2, 3], y=[1, 4, 9], mode="lines+markers")],
    layout=go.Layout(title="Squares")
)
fig.show()

Creates a figure from a scatter trace and an explicit layout, then displays the interactive chart.

When to use it

Trace-based charts

Build a chart from low-level graph-object traces.

Incremental construction

Create a chart progressively before displaying it.

Chart configuration

Apply shared axes, titles, and presentation settings.

Interview questions

QWhat does go.Figure create and what are its main inputs?

go.Figure is the graph-object constructor for a Plotly chart. It accepts trace data and an optional layout, and the resulting figure can be displayed with show().

Follow-up: How would you build a chart incrementally? Start with go.Figure(), then add traces with add_trace() and configure chart-wide properties with update_layout().

QHow do you initialize a figure with traces and layout?

Pass one trace or a list of traces through data, and use layout for chart-level configuration. A figure may also be initialized empty and filled later.

Follow-up: How can subplot figures be created? Use plotly.subplots.make_subplots(), or configure subplots on an existing figure with set_subplots().

QHow do traces relate to a Figure?

The constructor belongs to plotly.graph_objects and is commonly used with graph-object trace classes such as go.Scatter. It produces an interactive figure object that supports methods for adding and updating chart content.

Follow-up: What is a practical distinction between a trace and a layout? A trace represents plotted data, while layout controls shared presentation and axes settings.

  • plotly.graph_objects.Scatter
  • plotly.graph_objects.Layout
  • Figure.add_trace
  • Figure.update_layout
  • plotly.subplots.make_subplots

Source: Time series and date axes in Python - Plotly. Checked 2026-10-15.