GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — ENH: introduce PieContainer and pie_label method by rcomer · Pull Request #30733 · matplotlib/matplotlib Conversation
|
| rotate : bool, default: False | ||
| Rotate each label to the angle of the corresponding slice if true. | ||
|
|
||
| alignment : {'center', 'outer', 'auto'}, default: 'auto' |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
'center' is how the autopct labels of pie are aligned and 'outer' is how the labels of pie are aligned. We had some discussion about the horizontal alignment at #29152 (comment) and #29152 (comment), but I did not notice the extra complication for vertical alignment with rotate until I was writing the example. autopct does not have an associated rotate option, but I can report that rotated labels that were centred horizontally but not centred vertically looked bad!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I think we need to come up with a more generic concept. For a start, I'd say make your own type (i.e. copy the remove method) and define whatever minimal API is reasonable. If we know what kind of API we want to have based on this example it's easier to design a more general On a side-note we want this to not only be pure collections, but be a semantic entity, like Edit: The case is similar to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
If writing from scratch, I would mostly test the functionality on |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
867bd4a to
bed6636
Compare
There was an error while loading. Please reload this page.
|
OK, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
For complete backwards compatibility, we need "texts" to be returned as an empty list when labeldistance is In draft for now while I think about how to address that. Suggestions of course welcome! Edit: this is now addressed by the next push. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Apologies - just found some doc changes that I had missed before. None of the examples now unpack or index the return value. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| super().__init__(lines, **kwargs) | ||
|
|
||
|
|
||
| class PieContainer: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am unsure on the name. I'm tempted to call this just Pie on the background, that I envision this will become a compound semantic artist. The "Container" puts more focus on "aggregation of parts".
In that context, I'm pondering whether pie() could/should become essentially
def pie(self, *args, **kwargs): pie = Pie(*args, **kwargs) self.add_artist(pie) return pie
OTOH, full semantics may be more than we can easily achieve; e.g. assume a later pie.set_values(new_values) changes the number of wedges. How does that affect explicitly set lists of labels or wedge properties?
Recommendation: Let's stick with PieContainer for now, but make then name provisional. - It's not needed for the basic use case of
pie = ax.pie(...)
ax.pie_label(pie, ....)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've left some minor comments.
Overall a systematic and easy-to-review PR. Thanks for the effort.🚀
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks for all your reviewing work @timhoffm. Your latest suggestions seem good to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It just occurred to me that if someone is using pandas pie, they will not get the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
To be in the containers list we need at least a |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Does it make sense to have a container interface/ABC to spell out the membership requirements for the containers list? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
We need to define what exactly a container is. My understanding from the label machinery is that it is an artist that is realized through multiple base artists, but rather as an implementation detail. ErrorbarContainer uses multiple Line2D, but is logically still a single entity that shows up as one legend entry. I haven’t checked, but suspect that tracking containers explicitly in Axes may be done so that we can identify the artists to label (but it could also be that this was done purely to have a place to attach the involved artists to the figure, since historically we tracked different types of artists like lines, patches, etc. in their own lists and we certainly want to mix the lines of BarContainer with regular standalone lines). In contrast, Pie is a rather a concerted logical aggregation of multiple artists. A single label and legend entry does not make sense. I therefore believe that Pie is not a container as far as current container design goes. How to move forward? I wouldn’t jump extra hoops to support advanced plotting through the pandas plot API. It it’s a high-level API to ease plotting from dataframes, but you can always extract the column data and feed it to matplotlib if needed. we should specify the concept behind the type of aggregation we do with Pie more clearly. And we need to define how that is represented in internal structures. Is it one artist that can provide multiple legend entries? Or is it rather a grouping where the individual parts are tracked as separate entities in the Axes? Currently, and historically, wedges are added as individual patches. As long as we do this, we can live without adding Pie to the Axes as a minimal starting point. Agreed it would be nice to be able to retrieve it back, but it’s not that we are losing functionality. It’s just a yet to be implemented feature which requires additional design and refactoring, and I propose to rather do this as a follow up. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
OK, I am happy to just drop the latest commit here. I was thinking that we need to support adding (at least) two sets of labels - once we deprecate |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I can confirm that if you put something without a |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
OK, PR is now back to what @timhoffm already approved 😇 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
BarContainer dues not reasonably handle labels either. There's some low-level hack in bar() to make this work. matplotlib/lib/matplotlib/axes/_axes.py Lines 2544 to 2549 in 91b8a07
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Looks like it's doing an either use labels on individual artists or container level label. I think it's maybe a questionable API decision to make them mutually exclusive, but I don't think it's a hack. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Whatever you want to name it. The effect is that responsibility of label handling is distributed between the individual bars and the container. There is no easy way to change between the two approaches afterwards. But anyway, this is of no concern for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit you can take or leave but mostly fun 'cause I learned some new things.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| for frac, label, expl in zip(x, labels, explode): | ||
| x, y = center |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🤨 til that loops have local scoping starting in v3
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @story645
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Have I missed something I still need to do for this one? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks @rcomer for the new labeling capabilities! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…nd pie_label Co-Authored-By: Claude Opus 4.5 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Allow option to display absolute values for pie chart
There was an error while loading. Please reload this page.