Skip to content

Commit d1a8079

Browse files
committed
Made suggested changes
1 parent 0349e7d commit d1a8079

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

doc/users/next_whats_new/histogram_vectorized_parameters.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Vectorize ``hatch``, ``edgecolor``, ``facecolor``, ``linewidth`` and ``linestyle`` in *hist* methods
2-
----------------------------------------------------------------------------------------------------
1+
Vectorized ``hist`` style parameters
2+
------------------------------------
33

44
The parameters ``hatch``, ``edgecolor``, ``facecolor``, ``linewidth`` and ``linestyle``
55
of the `~matplotlib.axes.Axes.hist` method are now vectorized.
6-
This means that you can pass in unique parameters for each histogram that is generated
6+
This means that you can pass in individual parameters for each histogram
77
when the input *x* has multiple datasets.
88

99

galleries/examples/statistics/histogram_multihist.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@
5050
# Setting properties for each dataset
5151
# -----------------------------------
5252
#
53-
# Plotting bar charts with datasets differentiated using:
53+
# You can style the histograms individually by passing a list of values to the
54+
# following parameters:
5455
#
55-
# * edgecolors
56-
# * facecolors
57-
# * hatches
58-
# * linewidths
59-
# * linestyles
56+
# * edgecolor
57+
# * facecolor
58+
# * hatch
59+
# * linewidth
60+
# * linestyle
6061
#
6162
#
62-
# Edge-Colors
63+
# edgecolor
6364
# ...........................
6465

6566
fig, ax = plt.subplots()
@@ -74,7 +75,7 @@
7475
plt.show()
7576

7677
# %%
77-
# Face-Colors
78+
# facecolor
7879
# ...........................
7980

8081
fig, ax = plt.subplots()
@@ -88,7 +89,7 @@
8889
plt.show()
8990

9091
# %%
91-
# Hatches
92+
# hatch
9293
# .......................
9394

9495
fig, ax = plt.subplots()
@@ -102,7 +103,7 @@
102103
plt.show()
103104

104105
# %%
105-
# Linewidths
106+
# linewidth
106107
# ..........................
107108

108109
fig, ax = plt.subplots()
@@ -118,7 +119,7 @@
118119
plt.show()
119120

120121
# %%
121-
# LineStyles
122+
# linestyle
122123
# ..........................
123124

124125
fig, ax = plt.subplots()

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4612,18 +4612,18 @@ def test_hist_stacked_bar():
46124612
@check_figures_equal(extensions=["png"])
46134613
def test_hist_vectorized_params(fig_test, fig_ref, kwargs):
46144614
np.random.seed(19680801)
4615-
x = [np.random.randn(n) for n in [2000, 5000, 10000]]
4615+
xs = [np.random.randn(n) for n in [20, 50, 100]]
46164616

46174617
(axt1, axt2) = fig_test.subplots(2)
46184618
(axr1, axr2) = fig_ref.subplots(2)
46194619

46204620
for histtype, axt, axr in [("stepfilled", axt1, axr1), ("step", axt2, axr2)]:
4621-
_, bins, _ = axt.hist(x, bins=10, histtype=histtype, **kwargs)
4621+
_, bins, _ = axt.hist(xs, bins=10, histtype=histtype, **kwargs)
46224622

46234623
kw, values = next(iter(kwargs.items()))
4624-
for i, (xi, value) in enumerate(zip(x, values)):
4625-
axr.hist(xi, bins=bins, histtype=histtype, **{kw: value},
4626-
zorder=(len(x)-i)/2)
4624+
for i, (x, value) in enumerate(zip(xs, values)):
4625+
axr.hist(x, bins=bins, histtype=histtype, **{kw: value},
4626+
zorder=(len(xs)-i)/2)
46274627

46284628

46294629
@pytest.mark.parametrize('kwargs, patch_face, patch_edge',
@@ -4672,14 +4672,13 @@ def test_hist_emptydata():
46724672
ax.hist([[], range(10), range(10)], histtype="step")
46734673

46744674

4675-
def test_hist_none_patch():
4676-
# To cover None patches when excess labels are provided
4677-
labels = ["First", "Second"]
4678-
patches = [[1, 2]]
4675+
def test_hist_unused_labels():
4676+
# When a list with one dataset and N elements is provided and N labels, ensure
4677+
# that the first label is used for the dataset and all other labels are ignored
46794678
fig, ax = plt.subplots()
4680-
ax.hist(patches, label=labels)
4681-
_, lbls = ax.get_legend_handles_labels()
4682-
assert (len(lbls) < len(labels) and len(patches) < len(labels))
4679+
ax.hist([[1, 2, 3]], label=["values", "unused", "also unused"])
4680+
_, labels = ax.get_legend_handles_labels()
4681+
assert labels == ["values"]
46834682

46844683

46854684
def test_hist_labels():

0 commit comments

Comments
 (0)