-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Impaler343
wants to merge
26
commits into
matplotlib:main
Choose a base branch
from
Impaler343:histogram
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
49cbec6
Add support for multiple hatches, edgecolor and linewidth in histograms
Impaler343 7d32ed0
Add hatch, linewidth and edgecolor parameters to multihist example
Impaler343 fd45352
Add test for added parameters
Impaler343 bdfc2e7
Made changes concise according to suggestion
Impaler343 0f93187
Made a more detailed gallery example
Impaler343 0fa897a
Added whats new note, documentation for vectorization, doc fix
Impaler343 bd0ce7c
Added new test, and reverted changes in old test
Impaler343 2351cbd
Modified test to pass codecov, added plot in whats new entry
Impaler343 528baa1
Altered whats new entry, docs and gallery example
Impaler343 a9a60a6
Resolved edgecolor and facecolor setting
Impaler343 f6110d5
Minor fix
Impaler343 fc6a1ba
Fix docs
Impaler343 36e8a64
Modified files to include facecolor and added test
Impaler343 c6d19ed
Removed figsize from test
Impaler343 a55f7e7
Add multiple baseline image names
Impaler343 f40547d
Fixed test?
Impaler343 b69d32d
Fixed test?
Impaler343 a770e91
Removed parametrize usage
Impaler343 ab3b35f
Add baseline images
Impaler343 93fdac9
Add baseline image
Impaler343 6fa8870
Fix docs
Impaler343 f0c6544
Fix docs
Impaler343 a56811c
Deleted baseline images, changed test
Impaler343 73a30aa
Fix test
Impaler343 f2932c1
Fix test
Impaler343 969493a
Handled None array passing to color
Impaler343 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
doc/users/next_whats_new/histogram_vectorized_parameters.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Vectorize ``hatch``, ``edgecolor``, ``facecolor``, ``linewidth`` and ``linestyle`` in *hist* methods | ||
---------------------------------------------------------------------------------------------------- | ||
|
||
The parameters ``hatch``, ``edgecolor``, ``facecolor``, ``linewidth`` and ``linestyle`` | ||
of the `~matplotlib.axes.Axes.hist` method are now vectorized. | ||
This means that you can pass in unique parameters for each histogram that is generated | ||
when the input *x* has multiple datasets. | ||
|
||
|
||
.. plot:: | ||
:include-source: true | ||
:alt: Four charts, each displaying stacked histograms of three Poisson distributions. Each chart differentiates the histograms using various parameters: ax1 uses different linewidths, ax2 uses different hatches, ax3 uses different edgecolors, and ax4 uses different facecolors. Edgecolors have ax1 and ax3 as well to accentuate the differences between the histograms. | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
np.random.seed(19680801) | ||
|
||
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(9, 9)) | ||
|
||
data1 = np.random.poisson(5, 1000) | ||
data2 = np.random.poisson(7, 1000) | ||
data3 = np.random.poisson(10, 1000) | ||
|
||
labels = ["Data 1", "Data 2", "Data 3"] | ||
|
||
ax1.hist([data1, data2, data3], bins=range(17), histtype="step", stacked=True, | ||
edgecolor=["red", "green", "blue"], linewidth=[1, 2, 3]) | ||
ax1.set_title("Different linewidths") | ||
ax1.legend(labels) | ||
|
||
ax2.hist([data1, data2, data3], bins=range(17), histtype="barstacked", | ||
hatch=["/", ".", "*"]) | ||
ax2.set_title("Different hatch patterns") | ||
ax2.legend(labels) | ||
|
||
ax3.hist([data1, data2, data3], bins=range(17), histtype="bar", fill=False, | ||
edgecolor=["red", "green", "blue"], linestyle=["--", "-.", ":"]) | ||
ax3.set_title("Different linestyles") | ||
ax3.legend(labels) | ||
|
||
ax4.hist([data1, data2, data3], bins=range(17), histtype="barstacked", | ||
facecolor=["red", "green", "blue"]) | ||
ax4.set_title("Different facecolors") | ||
ax4.legend(labels) | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not seeing code that sets color=colors and you don't test the colors=set, facecolor=None, edgecolor=None case, so can you verify that case works as expected?
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.
colors
is already set around line 7017. And yes it works as the table mentioned. Should I add it to the tests with an only color test as well?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.
sorry, I read
colors = mcolors.to_rgba_array(color)
wrong 🤦♀️Um, yes, please add one "only color" case. Basically, the goal is to check that every combination in #28073 (comment) works as expected in the vectorized case - where hmm, easiest thing may then be 1 image with 10 subplots, one for each case, (And possibly label each case). I can also be sold on that being out of scope here/testing for the none vectorized case is good enough.
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.
which also, this is where check_figures equal could be useful b/c then you can use pytest to autobuild all the combinations by stacking parameterizations
https://docs.pytest.org/en/7.1.x/how-to/parametrize.html
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.
The image might be too cluttered with 10 subplots, I tried making a big image earlier, is a limit on the figsize?
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 dont think wecan use parametrization with image comparison tests as there is only one baseline image to compare from?
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.
yeah, that's why I was pushing paramterization + check_figures_equal
and there shouldn't be an issue w/ setting a figsize in the test far as I know