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

Skip to content

Commit 8fcc26e

Browse files
committed
Merge pull request #6494 from Carreau/stepfilled
FIX: Make edgecolors and facecolors the same when using stepfilled histogram.
2 parents ccb1072 + f0de8ce commit 8fcc26e

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6281,24 +6281,19 @@ def _normalize_input(inp, ename='input'):
62816281
xvals.append(x.copy())
62826282
yvals.append(y.copy())
62836283

6284-
if fill:
6285-
# add patches in reverse order so that when stacking,
6286-
# items lower in the stack are plottted on top of
6287-
# items higher in the stack
6288-
for x, y, c in reversed(list(zip(xvals, yvals, color))):
6289-
patches.append(self.fill(
6290-
x, y,
6291-
closed=True,
6292-
facecolor=c,
6293-
margins=margins))
6294-
else:
6295-
for x, y, c in reversed(list(zip(xvals, yvals, color))):
6296-
split = 2 * len(bins)
6297-
patches.append(self.fill(
6298-
x[:split], y[:split],
6299-
closed=False, edgecolor=c,
6300-
fill=False,
6301-
margins=margins))
6284+
#stepfill is closed, step is not
6285+
split = -1 if fill else 2 * len(bins)
6286+
# add patches in reverse order so that when stacking,
6287+
# items lower in the stack are plottted on top of
6288+
# items higher in the stack
6289+
for x, y, c in reversed(list(zip(xvals, yvals, color))):
6290+
patches.append(self.fill(
6291+
x[:split], y[:split],
6292+
closed=True if fill else None,
6293+
facecolor=c,
6294+
edgecolor=None if fill else c,
6295+
fill=fill if fill else None,
6296+
margins=margins))
63026297

63036298
# we return patches, so put it back in the expected order
63046299
patches.reverse()

lib/matplotlib/tests/test_axes.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import matplotlib.markers as mmarkers
2828
import matplotlib.patches as mpatches
2929
from numpy.testing import assert_allclose, assert_array_equal
30-
import warnings
3130
from matplotlib.cbook import IgnoredKeywordWarning
3231
import matplotlib.colors as mcolors
3332

@@ -36,6 +35,7 @@
3635
# different baseline images to prevent race conditions when nose runs
3736
# the tests with multiple threads.
3837

38+
3939
@image_comparison(baseline_images=['formatter_ticker_001',
4040
'formatter_ticker_002',
4141
'formatter_ticker_003',
@@ -1151,6 +1151,27 @@ def test_hist_steplog():
11511151
plt.hist(data_big, 100, histtype='stepfilled', log=True, orientation='horizontal')
11521152

11531153

1154+
@image_comparison(baseline_images=['hist_step_filled'], remove_text=True,
1155+
extensions=['png'])
1156+
def test_hist_step_filled():
1157+
np.random.seed(0)
1158+
x = np.random.randn(1000, 3)
1159+
n_bins = 10
1160+
1161+
kwargs = [{'fill': True}, {'fill': False}, {'fill': None}, {}]*2
1162+
types = ['step']*4+['stepfilled']*4
1163+
fig, axes = plt.subplots(nrows=2, ncols=4)
1164+
axes = axes.flatten()
1165+
1166+
for kg, _type, ax in zip(kwargs, types, axes):
1167+
ax.hist(x, n_bins, histtype=_type, stacked=True, **kg)
1168+
ax.set_title('%s/%s' % (kg, _type))
1169+
ax.set_ylim(ymin=-50)
1170+
1171+
patches = axes[0].patches
1172+
assert all([p.get_facecolor() == p.get_edgecolor() for p in patches])
1173+
1174+
11541175
@image_comparison(baseline_images=['hist_step_log_bottom'],
11551176
remove_text=True, extensions=['png'])
11561177
def test_hist_step_log_bottom():
@@ -1765,7 +1786,7 @@ def test_boxplot():
17651786
ax.set_ylim((-30, 30))
17661787

17671788
# Reuse testcase from above for a labeled data test
1768-
data={"x": [x, x]}
1789+
data = {"x": [x, x]}
17691790
fig, ax = plt.subplots()
17701791
ax.boxplot("x", bootstrap=10000, notch=1, data=data)
17711792
ax.set_ylim((-30, 30))

0 commit comments

Comments
 (0)