Donut Charts

Donut Charts#

A donut chart is a modified pie chart with an empty circle at the middle of the pie. We can create a donut chart by creating a graph object and specifying a value for the hole parameter. This example does not use plotly.express and instead creates the graph object manually.

import plotly.graph_objects as go # import statement
labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen'] # slice labels
values = [4500, 2500, 1053, 500] # slice values
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)]) # create figure
fig # show output

There’s a lot to get into in terms of the differences between plotly.express function syntax and plotly.graph_object syntax. For our purposes, we can focus on how values, labels, and parameters are passed to go.Figure() and go.Pie() to create the plot.