Skip to content

Commit 6372f1d

Browse files
authored
Merge pull request #17204 from anntzer/histstepzorder
Draw unfilled hist()s with the zorder of lines.
2 parents cc5ddce + abd3a25 commit 6372f1d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/api/api_changes_3.3/behaviour.rst

+5
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,8 @@ wx Timer interval
181181
~~~~~~~~~~~~~~~~~
182182
Setting the timer interval on a not-yet-started ``TimerWx`` won't start it
183183
anymore.
184+
185+
"step"-type histograms default to the zorder of `.Line2D`
186+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187+
This ensures that they go above gridlines by default. The old ``zorder`` can
188+
be kept by passing it as a keyword argument to `.Axes.hist`.

lib/matplotlib/axes/_axes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6769,7 +6769,8 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
67696769
closed=True if fill else None,
67706770
facecolor=c,
67716771
edgecolor=None if fill else c,
6772-
fill=fill if fill else None))
6772+
fill=fill if fill else None,
6773+
zorder=None if fill else mlines.Line2D.zorder))
67736774
for patch_list in patches:
67746775
for patch in patch_list:
67756776
if orientation == 'vertical':

lib/matplotlib/tests/test_axes.py

+12
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,18 @@ def test_hist_with_empty_input(data, expected_number_of_hists):
16311631
assert hists.shape[0] == expected_number_of_hists
16321632

16331633

1634+
@pytest.mark.parametrize("histtype, zorder",
1635+
[("bar", mpl.patches.Patch.zorder),
1636+
("step", mpl.lines.Line2D.zorder),
1637+
("stepfilled", mpl.patches.Patch.zorder)])
1638+
def test_hist_zorder(histtype, zorder):
1639+
ax = plt.figure().add_subplot()
1640+
ax.hist([1, 2], histtype=histtype)
1641+
assert ax.patches
1642+
for patch in ax.patches:
1643+
assert patch.get_zorder() == zorder
1644+
1645+
16341646
def contour_dat():
16351647
x = np.linspace(-3, 5, 150)
16361648
y = np.linspace(-3, 5, 120)

0 commit comments

Comments
 (0)