Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix bugs related to bottom kwarg in step histograms #2409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions 23 lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8319,18 +8319,18 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
hist_kwargs = dict(range=bin_range)

n = []
mlast = bottom
mlast = None
for i in xrange(nx):
# this will automatically overwrite bins,
# so that each histogram uses the same bins
m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
m = m.astype(float) # causes problems later if it's an int
if mlast is None:
mlast = np.zeros(len(bins)-1, m.dtype)
if normed and not stacked:
db = np.diff(bins)
m = (m.astype(float) / db) / m.sum()
if stacked:
if mlast is None:
mlast = np.zeros(len(bins)-1, m.dtype)
m += mlast
mlast[:] = m
n.append(m)
Expand Down Expand Up @@ -8421,6 +8421,12 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
x[0:2*len(bins)-1:2], x[1:2*len(bins)-1:2] = bins, bins[:-1]
x[2*len(bins)-1:] = x[1:2*len(bins)-1][::-1]

if bottom is None:
bottom = np.zeros(len(bins)-1, np.float)

y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = bottom, bottom
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]

if log:
if orientation == 'horizontal':
self.set_xscale('log', nonposx='clip')
Expand Down Expand Up @@ -8456,12 +8462,13 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,

xvals, yvals = [], []
for m in n:
# starting point for drawing polygon
y[0] = y[1]
# top of the previous polygon becomes the bottom
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]
if stacked:
# starting point for drawing polygon
y[0] = y[1]
# top of the previous polygon becomes the bottom
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]
# set the top of this polygon
y[1:2*len(bins)-1:2], y[2:2*len(bins)-1:2] = m, m
y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = m + bottom, m + bottom
if log:
y[y < minimum] = minimum
if orientation == 'horizontal':
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions 9 lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,15 @@ def test_hist_stacked_normed():
ax.hist((d1, d2), stacked=True, normed=True)


@image_comparison(baseline_images=['hist_step_bottom'], extensions=['png'], remove_text=True)
def test_hist_step_bottom():
# make some data
d1 = np.linspace(1, 3, 20)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.hist(d1, bottom=np.arange(10), histtype="stepfilled")


@image_comparison(baseline_images=['hist_stacked_bar'])
def test_hist_stacked_bar():
# make some data
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.