Here pct variable has been used to access the current value that is going to be added as a label. Is there a similar variable for the index? Where can I find other ‘ready-to-use’ variables for this method?
Do you mean you want to label each wedge with its index? There is not a automatic way to do that but you could pass the indices as the labels parameter, e.g.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
values = [4, 2, 5, 9]
indices = range(len(values))
ax.pie(values, labels=indices)
plt.show()
In case you are already using labels for something else, we will soon release Matplotlib v3.11, which will have a new pie_label method that allows adding multiple sets of labels.
I found a solution to this problem using enumerate(). Thanks for the discussion!
