It would be nice to be able to have the labels applied on top of pie chart slices, rather than on the edges. Likewise, it would be nice to have the percentages on the outside of the pie chart slices instead of on the inside.
Proposed solution
Allow an option to swap the autopct and label positions. Also, allow the autopct position to be autorotated via a flag like rotateautopct.
Hi @vitorfrois, I recommend that you wait until a few maintainers have chimed in on whether this feature should go into matplotlib and hashed out an API- if you have suggestions you're welcome to propose them. Otherwise (and possibly either way) this will get hashed out on the PR.
The request seems reasonable to me but I'm not sure whether the API would be simple enough to be feasible- do we want three more kwargs on this plotting method, is there a more straightforward way to do this (was thinking allow label and autoprct to take each other's kwargs but that will maybe be messy internal logic) or is it simple?
Actually it has a very simple solution.
At def pie(...):, a swaplabelpct=False parameter was added. Inside the function, I have the statement
if swaplabelpct: labeldistance, pctdistance = pctdistance, labeldistance+0.05
(the +0.05 allows some space between %s and the chart)
And when I print a pie chat with swaplabelpct=True, I get the following result:
If you've already implemented something, you're more than welcome to open the PR. I'm just trying to be upfront that it may not get in.
labeldistance+0.05
Does this padding work for all wedge sizes/ a wide range of percentages?
swaplabelpct=False
I think this is cleaner than my proposal (I was thinking of label and prct locations cause that would provide lots of flexibility) but I'm not totally sold on whether this or a more general solution makes more sense.
I'm not in favour of this request: labeldistance and pctdistance are both provided as kwargs. The user can swap these themselves, or put in whatever value they prefer, if they do not like the default values.
You can make it more explicit if you like, but the documentation is readily available - not everything needs to be spelled out explicitly in an example.
not everything needs to be spelled out explicitly in an example.
Yeah, but I think feature requests are good candidates for making more explicit, and here it's adding a section to an example rather than creating a new one. I'd honestly just move them next to each other in the docs but can't in this case 'cause of the signature (though the existing order doesn't match the signature either...)
ETA: maybe make the docstring more explict: Set to 1.5 to put autoprct outside, set to less than 1 to put labels inside?
Activity
vitorfrois commented on Dec 20, 2022
Hello, I'd like to contribute on this issue.
story645 commented on Dec 20, 2022
Hi @vitorfrois, I recommend that you wait until a few maintainers have chimed in on whether this feature should go into matplotlib and hashed out an API- if you have suggestions you're welcome to propose them. Otherwise (and possibly either way) this will get hashed out on the PR.
The request seems reasonable to me but I'm not sure whether the API would be simple enough to be feasible- do we want three more kwargs on this plotting method, is there a more straightforward way to do this (was thinking allow label and autoprct to take each other's kwargs but that will maybe be messy internal logic) or is it simple?
vitorfrois commented on Dec 20, 2022
Actually it has a very simple solution.

At def pie(...):, a swaplabelpct=False parameter was added. Inside the function, I have the statement
if swaplabelpct: labeldistance, pctdistance = pctdistance, labeldistance+0.05
(the +0.05 allows some space between %s and the chart)
And when I print a pie chat with swaplabelpct=True, I get the following result:
story645 commented on Dec 20, 2022
If you've already implemented something, you're more than welcome to open the PR. I'm just trying to be upfront that it may not get in.
Does this padding work for all wedge sizes/ a wide range of percentages?
I think this is cleaner than my proposal (I was thinking of label and prct locations cause that would provide lots of flexibility) but I'm not totally sold on whether this or a more general solution makes more sense.
jklymak commented on Dec 20, 2022
I'm not in favour of this request: labeldistance and pctdistance are both provided as kwargs. The user can swap these themselves, or put in whatever value they prefer, if they do not like the default values.
story645 commented on Dec 20, 2022
I didn't know about those and should have checked 😶 but then maybe the resolution here is to better documenting that by adding a section to https://matplotlib.org/devdocs/gallery/pie_and_polar_charts/pie_and_donut_labels.html#sphx-glr-gallery-pie-and-polar-charts-pie-and-donut-labels-py
jklymak commented on Dec 20, 2022
You can make it more explicit if you like, but the documentation is readily available - not everything needs to be spelled out explicitly in an example.
story645 commented on Dec 20, 2022
Yeah, but I think feature requests are good candidates for making more explicit, and here it's adding a section to an example rather than creating a new one. I'd honestly just move them next to each other in the docs but can't in this case 'cause of the signature (though the existing order doesn't match the signature either...)

ETA: maybe make the docstring more explict: Set to 1.5 to put autoprct outside, set to less than 1 to put labels inside?
oscargus commented on Dec 20, 2022
Are pctdistance and labeldistance using the same ""units"? Not so clear from the descriptions in that case....
jklymak commented on Dec 21, 2022
They are the same, but they should be spelled the same here.
timhoffm commented on Dec 21, 2022
Just do it. Reorder according to the signature and then move shadow one place. Nobody will notice.
Additionally, we can start a kwarg only deprecation at explode to have the ability of reordering the signature in the future.
23 remaining items
expanded basic pie example
expanded basic pie example
expanded basic pie example
expanded basic pie example
expanded basic pie example
oscargus commented on Mar 5, 2023
I think that this can be closed now.
There is an example explicitly showing this: https://matplotlib.org/devdocs/gallery/pie_and_polar_charts/pie_features.html#swap-label-and-autopct-text-positions
and the documentation is updated:
https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.pie.html#matplotlib.axes.Axes.pie
added hatch kwarg arg + tests + what's new (w/ alt)
expanded basic pie example
added hatch kwarg arg + tests + what's new (w/ alt)
expanded basic pie example
added hatch kwarg arg + tests + what's new (w/ alt)
expanded basic pie example