FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[ENH]: Ability to Swap autopct and label positions · Issue #24789 · matplotlib/matplotlib · GitHub

Repository navigation

[ENH]: Ability to Swap autopct and label positions #24789

Closed

Description

Problem

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.

Activity

  1. vitorfrois commented on Dec 20, 2022

    Hello, I'd like to contribute on this issue.

  2. story645 commented on Dec 20, 2022

    Member

    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?

  3. 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:

  4. story645 commented on Dec 20, 2022

    Member

    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.

  5. jklymak commented on Dec 20, 2022

    Member

    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.

  6. story645 commented on Dec 20, 2022

    Member

    I'm not in favour of this request: labeldistance and pctdistance are both provided as kwargs.

    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

  7. jklymak commented on Dec 20, 2022

    Member

    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.

  8. story645 commented on Dec 20, 2022

    Member

    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?

  9. oscargus commented on Dec 20, 2022

    Member

    Are pctdistance and labeldistance using the same ""units"? Not so clear from the descriptions in that case....

  10. jklymak commented on Dec 21, 2022

    Member

    They are the same, but they should be spelled the same here.

  11. timhoffm commented on Dec 21, 2022

    Member

    I'd honestly just move them next to each other in the docs but can't in this case 'cause of the signature

    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.

  12. 23 remaining items

  13. oscargus commented on Mar 5, 2023

    Member
  14. added this to the v3.7.0 milestone on Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL