-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add support for multiple hatches, edgecolors and linewidths in histograms #28073
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1a6ec0f
Add support for multiple hatches, edgecolor and linewidth in histograms
Impaler343 0e52daa
Add hatch, linewidth and edgecolor parameters to multihist example
Impaler343 34df06a
Add test for added parameters
Impaler343 4fcb709
Reduced to 13 tests in total
Impaler343 347ce22
Added color semantics test and modified vectorized parameters test
Impaler343 d7ffeaa
Added None patch test
Impaler343 9024be4
Heading edit
Impaler343 3bfca5f
Simplified test
Impaler343 6029e32
Updated none patch test
Impaler343 0349e7d
Made None patch condition explicit
Impaler343 d1a8079
Made suggested changes
Impaler343 9a813f4
Added version-added directive
Impaler343 43ce57d
Made suggested changes
Impaler343 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 hidden or 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 @@ | ||
Vectorized ``hist`` style parameters | ||
------------------------------------ | ||
|
||
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 individual parameters for each histogram | ||
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: top left uses different linewidths, top right uses different hatches, bottom left uses different edgecolors, and bottom right uses different facecolors. Each histogram on the left side also has a different edgecolor. | ||
|
||
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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.