Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 528baa1

Browse files
committed
Altered whats new entry, docs and gallery example
1 parent 2351cbd commit 528baa1

File tree

3 files changed

+65
-39
lines changed

3 files changed

+65
-39
lines changed

doc/users/next_whats_new/histogram_vectorized_parameters.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ Vectorize ``hatch``, ``edgecolor``, ``linewidth`` and ``linestyle`` in *hist* me
22
---------------------------------------------------------------------------------------
33

44
The parameters ``hatch``, ``edgecolor``, ``linewidth`` and ``linestyle`` of the `~matplotlib.axes.Axes.hist` method are now vectorized.
5-
This means that you can pass a list of values to these parameters, and the values will be applied to each dataset in the histogram.
5+
This means that you can pass in unique parameters for each histogram that is generated when the input *x* has multiple datasets.
66
Note that the ``facecolor`` parameter is not vectorized, but the required behavior can be achieved by passing a list of colors to the ``color`` parameter.
77

88
.. plot::
99
:include-source: true
10-
:alt: Three charts, identified as ax1, ax2 and ax3, include plots of three random datasets. The first, second and third plots have datasets differentiated by linewidths, hatches and linestyles, respectively. Edgecolors are used in all of the plots to accentuate the differences.
10+
:alt: Three charts, identified as ax1, ax2 and ax3, show a stacking of three histograms representing Poisson distributions. The histograms in ax1, ax2, and ax3 are differentiated by linewidths, hatches and linestyles, respectively. In ax1, ax2, and ax3, each histogram is bordered by a different color.
1111

1212
import matplotlib.pyplot as plt
1313
import numpy as np

galleries/examples/statistics/histogram_multihist.py

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,75 +27,100 @@
2727
fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)
2828

2929
colors = ['red', 'tan', 'lime']
30-
ax0.hist(x, n_bins, density=True, histtype="bar", color=colors, label=colors)
30+
ax0.hist(x, n_bins, density=True, histtype='bar', color=colors, label=colors)
3131
ax0.legend(prop={'size': 10})
3232
ax0.set_title('bars with legend')
3333

34-
ax1.hist(x, n_bins, density=True, histtype="bar", stacked=True)
34+
ax1.hist(x, n_bins, density=True, histtype='bar', stacked=True)
3535
ax1.set_title('stacked bar')
3636

37-
ax2.hist(x, n_bins, histtype="step", stacked=True, fill=False)
37+
ax2.hist(x, n_bins, histtype='step', stacked=True, fill=False)
3838
ax2.set_title('stack step (unfilled)')
3939

4040
# Make a multiple-histogram of data-sets with different length.
4141
x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]
42-
ax3.hist(x_multi, n_bins, histtype="bar")
42+
ax3.hist(x_multi, n_bins, histtype='bar')
4343
ax3.set_title('different sample sizes')
4444

4545
fig.tight_layout()
4646
plt.show()
4747

4848
# %%
49-
# Setting properties for each sample set
50-
# --------------------------------------
49+
# -----------------------------------
50+
# Setting properties for each dataset
51+
# -----------------------------------
5152
#
52-
# Plotting a bar chart with sample sets differentiated using:
53+
# Plotting bar charts with datasets differentiated using:
5354
#
5455
# * edgecolors
5556
# * hatches
5657
# * linewidths
5758
# * linestyles
5859
#
59-
# Also, these parameters can be specified for all types of
60-
# histograms (stacked, step, etc.) and not just for the *bar*
61-
# type histogram as shown in the example.
60+
#
61+
# Histograms with Edge-Colors
62+
# ...........................
6263

63-
hatches = ["-", "o", "x"]
64-
linewidths = [1, 2, 3]
65-
edgecolors = ["green", "red", "blue"]
66-
linestyles = ["-", ":", "--"]
64+
fig, ax = plt.subplots()
6765

68-
fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)
66+
edgecolors = ['green', 'red', 'blue']
6967

70-
ax0.hist(
71-
x, n_bins, density=True, fill=False, histtype="bar",
68+
ax.hist(
69+
x, n_bins, fill=False, histtype="step", stacked=True,
7270
edgecolor=edgecolors, label=edgecolors
7371
)
74-
ax0.legend(prop={"size": 10})
75-
ax0.set_title("Bars with Edgecolors")
72+
ax.legend()
73+
ax.set_title('Stacked Steps with Edgecolors')
7674

77-
ax1.hist(
78-
x, n_bins, density=True, histtype="bar",
79-
hatch=hatches, label=hatches
80-
)
81-
ax1.legend(prop={"size": 10})
82-
ax1.set_title("Bars with Hatches")
75+
plt.show()
76+
77+
78+
# Histograms with Hatches
79+
# .......................
80+
81+
fig, ax = plt.subplots()
82+
83+
hatches = [".", "o", "x"]
84+
85+
ax.hist(x, n_bins, histtype="barstacked", hatch=hatches, label=hatches)
86+
ax.legend()
87+
ax.set_title("Hatches on Stacked Bars")
88+
89+
plt.show()
8390

84-
ax2.hist(
85-
x, n_bins, density=True, fill=False, histtype="bar",
86-
linewidth=linewidths, edgecolor=edgecolors, label=linewidths
91+
92+
# Histograms with Linewidths
93+
# ..........................
94+
95+
fig, ax = plt.subplots()
96+
97+
linewidths = [1, 2, 3]
98+
edgecolors = ["green", "red", "blue"]
99+
100+
ax.hist(
101+
x, n_bins, fill=False, histtype="bar", linewidth=linewidths,
102+
edgecolor=edgecolors, label=linewidths,
87103
)
88-
ax2.legend(prop={"size": 10})
89-
ax2.set_title("Bars with Linewidths")
104+
ax.legend()
105+
ax.set_title("Bars with Linewidths")
90106

91-
ax3.hist(
92-
x, n_bins, density=True, fill=False, histtype="bar",
93-
linestyle=linestyles, edgecolor=edgecolors, label=linestyles
107+
plt.show()
108+
109+
110+
# Histograms with LineStyles
111+
# ...........................
112+
113+
fig, ax = plt.subplots()
114+
115+
linestyles = ['-', ':', '--']
116+
117+
ax.hist(
118+
x, n_bins, fill=False, histtype='bar', linestyle=linestyles,
119+
edgecolor=edgecolors, label=linestyles
94120
)
95-
ax3.legend(prop={"size": 10})
96-
ax3.set_title("Bars with Linestyles")
121+
ax.legend()
122+
ax.set_title('Bars with Linestyles')
97123

98-
fig.tight_layout()
99124
plt.show()
100125

101126
# %%

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6938,7 +6938,8 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
69386938
69396939
**kwargs
69406940
`~matplotlib.patches.Patch` properties. The following properties
6941-
additionally accept lists of property values, one element for each dataset:
6941+
additionally accepts a sequence of properties values corresponding
6942+
to the datasets in *x*:
69426943
*edgecolors*, *linewidths*, *linestyles*, *hatches*.
69436944
69446945
See Also

0 commit comments

Comments
 (0)