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

Plotly · Class

go.Pie

go.Pie defines a Plotly pie trace from sector labels and values. Add it to a go.Figure to render an interactive pie chart.

How it works

Construct a pie trace with go.Pie, supplying sector names through labels and their magnitudes through values. Add the trace to a go.Figure, then render or further configure it with Plotly's figure APIs.

Syntax

go.Pie([arg, automargin, customdata, …])

Key points

  • Use values to provide the quantities represented by the pie sectors.
  • Use labels to name the sectors; the labels correspond to the supplied values.
  • Set marker.colors to customize the colors assigned to sectors.
  • Choose go.Pie when the lower-level graph-object interface is a better fit than Plotly Express.

Example: Basic pie chart

import plotly.graph_objects as go

labels = ["Oxygen", "Hydrogen", "Carbon dioxide", "Nitrogen"]
values = [4500, 2500, 1053, 500]

fig = go.Figure(go.Pie(labels=labels, values=values))
fig.show()

Creates a figure containing a pie trace whose sectors use labels and values.

When to use it

Part-to-whole visualization

Show how a total is divided among named categories.

Graph-object chart construction

Build a chart with explicit trace attributes and figure composition.

Custom sector styling

Apply a deliberate palette to individual sectors.

Interview questions

QWhat is go.Pie used for, and which inputs define its sectors?

go.Pie is a generic graph-object class for defining a pie trace. The sector data is supplied with values, while sector names are supplied with labels.

Follow-up: How would you style sector colors? Set marker.colors on the pie trace, for example with go.Pie(marker_colors=[...]).

QHow do you create and display a basic pie chart with Plotly graph objects?

Create the trace with go.Pie(...), pass it to go.Figure, and call show() to display the chart. The documented basic pattern uses parallel labels and values sequences.

Follow-up: How can the chart be made into a donut? Configure the pie trace's hole attribute with a value greater than zero.

QHow are pie-sector colors configured?

The trace's sector colors are controlled by marker.colors. This lets each sector receive a chosen color sequence instead of relying only on the default palette.

Follow-up: How can you control the order of sectors? Use the pie trace's ordering-related attributes, such as sort, when the desired order differs from the input order.

  • plotly.graph_objects.Figure
  • plotly.express.pie
  • marker.colors
  • labels
  • values

Source: Pie charts in Python. Checked 2026-10-15.