Skip to content

Commit

Permalink
Make edgecolors and facecolors the same when using stepfilled histogram.
Browse files Browse the repository at this point in the history
Closes matplotlib#6493

Expand the test to try the 6 histype/fill combinations, and in
particular change yaxis min limit to see if the paths are closed or not.
  • Loading branch information
Carreau committed May 29, 2016
1 parent 6ef64a6 commit 8bd8f12
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
9 changes: 5 additions & 4 deletions lib/matplotlib/axes/_axes.py
Expand Up @@ -6281,17 +6281,18 @@ def _normalize_input(inp, ename='input'):
xvals.append(x.copy())
yvals.append(y.copy())

#stepfill is closed, step is not
split = -1 if fill else 2 * len(bins)
# add patches in reverse order so that when stacking,
# items lower in the stack are plottted on top of
# items higher in the stack
split = -1 if fill else 2 * len(bins)
for x, y, c in reversed(list(zip(xvals, yvals, color))):
patches.append(self.fill(
x[:split], y[:split],
closed=not fill,
fill=fill,
edgecolor=None if fill else c,
closed=True if fill else None,
facecolor=c,
edgecolor=None if fill else c,
fill=fill if fill else None,
margins=margins))

# we return patches, so put it back in the expected order
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 16 additions & 7 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -1153,14 +1153,23 @@ def test_hist_steplog():

@image_comparison(baseline_images=['hist_step_filled'], extensions=['png'])
def test_hist_step_filled():
np.random.seed(0)
n_bins = 10
np.random.seed(0)
x = np.random.randn(1000, 3)
fig, ax = plt.subplots()
ax.hist(x, n_bins, histtype='step', fill=True, stacked=True)
#display anything that would be hidden by X Axis, like closed/unclosed edge path.
ax.set_ylim(ymin=-50)
patches= ax.patches
n_bins=10

kwargs = [{'fill':True}, {'fill':False},{'fill':None},{}]*2
types = ['step']*4+['stepfilled']*4
fig, axes = plt.subplots(nrows=2, ncols=4)
axes = axes.flatten()


for kg,_type,ax in zip(kwargs, types, axes):
ax.hist(x, n_bins, histtype=_type, stacked=True,**kg)
ax.set_title('%s/%s' % (kg, _type) )
ax.set_ylim(ymin=-50)

patches= axes[0].patches
all([p.get_facecolor() == p.get_edgecolor() for p in patches])
all([p.get_facecolor() == p.get_edgecolor() for p in patches])


Expand Down

0 comments on commit 8bd8f12

Please sign in to comment.