Part-to-whole breakdown
Show how a total is divided among named categories.
Plotly · Function
px.pie creates an interactive pie chart from tabular data. It maps numeric values to sector sizes and categories to labels, with options for hover content, naming, and further figure customization.
px.pie builds a complete Plotly figure from tabular data. Pass a data source plus the column or sequence for sector sizes and another for labels; optional arguments configure grouping, coloring, hover content, text, and layout before the figure is rendered or further updated.
plotly.express.pie(data_frame=None, names=None, values=None, color=None, facet_row=None, facet_col=None, facet_col_wrap=0, facet_row_spacing=None, facet_col_spacing=None, hover_name=None, hover_data=None, custom_data=None, category_orders=None, labels=None, color_discrete_sequence=None, color_discrete_map=None, marginal=None, title=None, template=None, width=None, height=None, opacity=None, hole=None, animation_frame=None, animation_group=None, range_color=None, color_continuous_scale=None, color_continuous_midpoint=None, symbol=None, symbol_sequence=None, symbol_map=None, text=None, text_template=None, text_auto=False, groupnorm=None, hover_data=None, **kwargs)A Plotly figure object.
values to the numeric data that determines each sector's magnitude.names to the categories shown as sector labels.hover_data to select additional columns for hover display.labels to provide human-friendly display names for columns.fig.update_traces for trace-level pie settings such as displayed text; use fig.update_layout for layout changes.import plotly.express as px
df = px.data.gapminder().query("year == 2007 and continent == 'Europe'")
fig = px.pie(df, values="pop", names="country", title="European population")
fig.show()Creates and displays a pie chart whose sector sizes come from population and labels come from country.
Show how a total is divided among named categories.
Display population, sales, or other measures by country or category.
Expose extra fields when users hover over sectors.
values and names control?px.pie creates a pie-chart figure from supplied data. The values argument determines sector sizes, while names supplies sector labels.
Follow-up: How would you change chart details after construction? Use fig.update_traces for trace attributes and fig.update_layout for layout attributes.
A typical call passes a dataframe as the first argument, then identifies its population and country columns with values and names. The returned figure can be displayed with fig.show().
Follow-up: How can hover content be customized? Pass hover_data to control which columns appear in the hover information.
px.pie return and how is it used?Plotly Express can create the complete figure in one call, such as px.pie(df, values='pop', names='country', title=...). The figure is then available for rendering or further configuration.
Follow-up: Which related chart types are suitable for hierarchical part-to-whole data? Plotly Express also provides sunburst, treemap, and icicle.
plotly.express.sunburstplotly.express.treemapplotly.express.icicleFigure.update_tracesFigure.update_layout