Doughnut

A doughnut chart is similar to a pie chart, but with a hole in the center. This space can be used to show more information.

data = [
    {'value': 1048, 'name': 'Search Engine'},
    {'value': 735, 'name': 'Direct'},
    {'value': 580, 'name': 'Email'},
    {'value': 484, 'name': 'Union Ads'},
    {'value': 300, 'name': 'Video Ads'}
]
s.plt.doughnut(data=data, names='name', values='value', order=1)

# Same data as for the stacked barcharts
df = pd.read_csv('../data/test_stack_distribution.csv')

value_columns = [col for col in df.columns if col != "Segment"]
df = df[['Segment'] + value_columns]

doughnut_data = pd.DataFrame(columns=["name", "value"])
df_transposed = df.transpose().reset_index().drop(0)
value_columns = [col for col in df_transposed.columns if col != "index"]
doughnut_data["value"] = df_transposed[value_columns].apply(lambda row: sum(row), axis=1)
doughnut_data["name"] = df_transposed['index']

s.plt.doughnut(
    data=doughnut_data, values='value', names='name', 
    order=2, rows_size=3, cols_size=6
)

Last updated