-
-
Notifications
You must be signed in to change notification settings - Fork 8k
DOC: simplify hat graph example #30459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0473092
to
909a928
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simplification!
xytext=(0, 4), # 4 points vertical offset. | ||
textcoords='offset points', | ||
ha='center', va='bottom') | ||
|
||
values = np.asarray(values) | ||
x = np.arange(values.shape[1]) | ||
ax.set_xticks(x, labels=xlabels) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this? I believe grouped_bar(..., tick_labels=...)
already cares for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops, yes.
|
||
# Draw the hats | ||
bars = ax.grouped_bar( | ||
(values - heights0).T, bottom=heights0, tick_labels=xlabels, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight preference to inline heights0 = values[0]
. I think that extra variable made sense when we had heights
in the for loop, but now only introduces additional mental load without any benefit.
(values - heights0).T, bottom=heights0, tick_labels=xlabels, | |
(values - values[0]).T, bottom=values[0], tick_labels=xlabels, |
# Remove the color that would otherwise show in the first group's legend entry | ||
bars.bar_containers[0].patches[0].set_facecolor('none') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better do as grouped_bar(..., color=['none', 'C1'])
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually did that first, but then noticed the docstring assumes an arbitrary number of groups (M). The linked paper only uses two groups. I didn’t find many examples with an image search, but this does show more groups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left it for now, but happy to restrict the function to two groups. I was also not a particular fan of this line when I wrote it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. Since the colors don’t need to be the exact length, you could do color=[„none“] + all_colors_in_the_color_cycle
. That would also make the first color C0, which may be more appropriate.
Or slice all_colors_in_the_color_cycle
to the appropriate size if you want to be more explicit.
PR summary
We can use
grouped_bar
andbar_label
to replace the bespoke logic in this example.PR checklist