Part-to-whole visualization
Show how a total is divided among named categories.
Plotly · Class
go.Pie defines a Plotly pie trace from sector labels and values. Add it to a go.Figure to render an interactive pie chart.
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.
go.Pie([arg, automargin, customdata, …])values to provide the quantities represented by the pie sectors.labels to name the sectors; the labels correspond to the supplied values.marker.colors to customize the colors assigned to sectors.go.Pie when the lower-level graph-object interface is a better fit than Plotly Express.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.
Show how a total is divided among named categories.
Build a chart with explicit trace attributes and figure composition.
Apply a deliberate palette to individual sectors.
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=[...]).
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.
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.Figureplotly.express.piemarker.colorslabelsvalues