plot_donut_chart()

Renders a donut (ring) chart with a hollow center for displaying summary text. Designed for part-of-whole compositions with up to ~8 segments. Each segment is colored with a continuous gradient.

Quick Example

import pandas as pd
import clean_charts as cc

df = pd.DataFrame({
    "Source": ["Solar", "Wind", "Nuclear", "Natural Gas", "Coal"],
    "TWh": [1200, 1500, 2500, 3000, 1800]
})

cc.plot_donut_chart(
    data=df,
    title="Global Energy Mix",
    subtitle="Projected generation in 2030 (TWh)",
    center_label="10,000\nTWh"
)
Donut
Example output for Donut.

Data Requirements

  • Column 0 — Segment labels (str)
  • Column 1 — Numeric values (auto-normalized to percentages)

Parameters

Parameter Type Default Scope Description
datapd.DataFrameBuilt-inCommon2-column DataFrame: [Labels, Values].
output_pathstr | NoneNoneCommonFile path to save.
widthint | None600CommonImage width in pixels.
heightint | NoneAutoCommonImage height in pixels.
aspect_ratiostr | NoneNoneCommon"square", "landscape", etc.
titlestr | NoneNoneCommonBold header text.
subtitlestr | NoneNoneCommonSecondary text.
bg_colorstr | None"#f4f3f0"CommonBackground hex color.
scale_textboolTrueCommonScale fonts proportionally.
value_suffixstr""CommonString appended to legend values.
show_percentagesboolFalseCommonAppend percentage to legend labels.
start_colorstr"#000000"UniqueGradient start color for the first segment.
end_colorstr"#2323FF"UniqueGradient end color for the last segment.
center_labelstr | NoneNoneUniqueBold text inside the ring center. Use \n for multiline (e.g., "$42M\nTotal").
hole_radiusfloatAutoUniqueInner hole as fraction of outer radius (0–1).
start_anglefloat90UniqueAngle (degrees) to start drawing the first wedge.
donut_radiusfloatAutoUniqueOuter radius as fraction of available chart height.

Common Scenarios

Hero Metric Donut

df = pd.DataFrame({
    "Source": ["Solar", "Wind", "Nuclear", "Natural Gas", "Coal"],
    "TWh": [1200, 1500, 2500, 3000, 1800]
})

cc.plot_donut_chart(
    data=df,
    title="Revenue Breakdown",
    center_label="$42M\nTotal Revenue",
    show_percentages=True
)
Donut
Example output for Donut.

Custom Gradient

df = pd.DataFrame({
    "Source": ["Solar", "Wind", "Nuclear", "Natural Gas", "Coal"],
    "TWh": [1200, 1500, 2500, 3000, 1800]
})

cc.plot_donut_chart(
    data=df,
    title="Revenue Breakdown",
    center_label="$42M\nTotal Revenue",
    show_percentages=True,
    start_color="#0A1F13",
    end_color="#FFED29"
)
Donut
Example output for Donut.