go.Pie is a Plotly Graph Objects trace for turning grouped labels and values into pie-chart sectors. Labels appear in the color legend, while values determine each sector's size. section 6.5.2
Create a donut chart
Group data by a dimension, then add one go.Pie trace to a Figure. Setting hole=0.4 changes the pie into a donut chart.
Listing 6.11 Displaying a pie chart
import plotly.graph_objects as go
from data_wrangling import get_metric_grouped_by_dimension
def get_pie_chart(df, metric, dimension):
data = get_metric_grouped_by_dimension(df, metric, dimension)
fig = go.Figure()
fig.add_trace(
go.Pie(labels=data[dimension], values=data['Value'], hole=0.4)
)
return fig
Use the compact implementation to inspect the relationship between grouped data, labels, values, and the donut hole. section 6.5.2
