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
Add support for multiple hatches, edgecolors and linewidths in histograms #28073
base: main
Are you sure you want to change the base?
Conversation
I'd suggest showing what this does with an example either in the GitHub pr description, or ideally in the gallery |
I'm not really sure if I need to add a new test or just modify an exisiting one(test_hist_stacked_bar) in test_axes.py |
I guess there are two things here:
|
pinging @story645 for review. The failing tests are unrelated |
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.
also needs updated documentation that the patch properties are now vectorized (@timhoffm any concerns here?)
lib/matplotlib/axes/_axes.py
Outdated
if 'hatch' in kwargs: | ||
kwargs['hatch'] = next(hatches) | ||
if 'edgecolor' in kwargs: | ||
kwargs['edgecolor'] = next(edgecolors) | ||
if 'linewidth' in kwargs: | ||
kwargs['linewidth'] = next(linewidths) |
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 you use the kwarg names directly instead of this if chain? kinda like how it's implemented in pie
matplotlib/lib/matplotlib/axes/_axes.py
Lines 3339 to 3344 in 80b08bd
w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2), | |
360. * max(theta1, theta2), | |
facecolor=get_next_color(), | |
hatch=next(hatch_cycle), | |
clip_on=False, | |
label=label) |
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.
yep, makes sense
ax0.hist(x, n_bins, density=True, histtype='bar', color=colors, | ||
label=colors, hatch=['o', '*', '.'], | ||
edgecolor=['black', 'red', 'blue'], linewidth=[1, 2, 3]) | ||
ax0.legend(prop={'size': 10}) | ||
ax0.set_title('bars with legend') |
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.
my bias is to not do all of these in one example because I think it becomes really busy and you don't need it here because you can do it in the next line. Here's how I do it, but you don't have to: https://matplotlib.org/devdocs/gallery/pie_and_polar_charts/pie_features.html#sphx-glr-gallery-pie-and-polar-charts-pie-features-py
PR summary
Closes #26718 Distributes keyword args passed to each Patch using a cycler. Probably not the best way to do this?
PR checklist