Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Impaler343
Copy link
Contributor

@Impaler343 Impaler343 commented Apr 13, 2024

PR summary

Closes #26718 Distributes keyword args passed to each Patch using a cycler. Probably not the best way to do this?

PR checklist

@jklymak
Copy link
Member

jklymak commented Apr 13, 2024

I'd suggest showing what this does with an example either in the GitHub pr description, or ideally in the gallery

@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Apr 14, 2024
@Impaler343
Copy link
Contributor Author

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

@oscargus
Copy link
Contributor

I guess there are two things here:

  1. Add/modify an example in the gallery to illustrate how it is used. (Will be easier for the reviewers to get an idea of how it is used etc.)
  2. Add a test to get the code coverage up and make sure no one breaks it later. Maybe there is some old example that one can "hi-jack", but otherwise create a new test with all the bells and whistles turned on.

@Impaler343
Copy link
Contributor Author

pinging @story645 for review. The failing tests are unrelated

Copy link
Member

@story645 story645 left a 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?)

Comment on lines 7190 to 7195
if 'hatch' in kwargs:
kwargs['hatch'] = next(hatches)
if 'edgecolor' in kwargs:
kwargs['edgecolor'] = next(edgecolors)
if 'linewidth' in kwargs:
kwargs['linewidth'] = next(linewidths)
Copy link
Member

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

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, makes sense

lib/matplotlib/axes/_axes.py Outdated Show resolved Hide resolved
Comment on lines +30 to 34
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')
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: examples files in galleries/examples New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: stacked histogram does not properly handle edgecolor and hatches
4 participants