I would like to add percentage values for each of the labels and layers within my three-layered donut plot.
The following code generates the three layer donut plot and legend appropriately. However, it messes up the display of the percentage values (see output figure at bottom of this question).
Current solutions at stack overflow or elsewhere only work for adding percentage values to pie/donut chart (eg: How do I use matplotlib autopct? ) but I have three layers/levels to my pie/donut chart. My code follows below:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
fig.set_figheight(7)
fig.set_figwidth(22)
ax1 = fig.add_subplot(121)
first_labels = ["Bonjovi", "Superman", "Darius_royale", "Stargazer_1991_viz", "Obligatory_Vis1", "Gertrude", 'Trimbel', "Olio", "Iniwaka"]
first_sizes = [2000, 300, 200, 100, 100, 150, 40, 30, 700]
second_sizes = [1000, 200, 200, 400, 500, 40, 1, 1, 1000]
third_sizes = [500, 300, 400, 500, 400, 100, 5, 2, 800]
flatui = (sns.diverging_palette(20, 250, n=8))
bigger = plt.pie(first_sizes, colors=flatui, startangle=90, frame=True, radius = 1,
wedgeprops={'edgecolor':'k'}, autopct = '%1.1%%f')
smaller = plt.pie(second_sizes, colors=flatui, radius=0.9, startangle=90,
wedgeprops={'edgecolor':'k'}, autopct = '%1.1%%f')
smallest = plt.pie(third_sizes, colors=flatui, radius=0.8, startangle=90,
wedgeprops={'edgecolor':'k'}, autopct = '%1.1%%f')
centre_circle = plt.Circle((0, 0), 0.7, color='white', linewidth=0)
plt.gca().add_artist(centre_circle)
# add legend to current ax:
plt.gca().legend(first_labels, loc='center right', bbox_to_anchor=(1,0,.4,1), frameon = True)
plt.show();
The results of the above code look as follows:
Can somebody please guide me on how to get the percentage values to display neatly within each donut ring?