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

Feature stack base #1671

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 9 commits into from
Jan 27, 2013
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
pep8 compliance
  • Loading branch information
Tillsten authored and dmcdougall committed Jan 26, 2013
commit b21b34887cd4602474b064bb9e489e6c40e1b5b4
29 changes: 15 additions & 14 deletions 29 lib/matplotlib/stackplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ def stackplot(axes, x, *args, **kwargs):

baseline = kwargs.pop('baseline', 'zero')
# Assume data passed has not been 'stacked', so stack it here.
y_stack = np.cumsum(y, axis=0)
stack = np.cumsum(y, axis=0)

r = []
if baseline == 'zero':
first_line = 0.

elif baseline == 'sym':
first_line = -np.sum(y, 0) * 0.5
y_stack += first_line[None, :]
first_line = -np.sum(y, 0) * 0.5
stack += first_line[None, :]

elif baseline == 'wiggle':
m = y.shape[0]
first_line = (y * (m - 0.5 - np.arange(0, m)[:, None])).sum(0)
first_line /= -m
y_stack += first_line
stack += first_line

elif baseline == 'weighted_wiggle':
#TODO: Vectorize this stuff.
Expand All @@ -83,29 +83,30 @@ def stackplot(axes, x, *args, **kwargs):
for j in range(m):
if i == 0:
increase = y[j, i]
moveUp = 0.5
move_up = 0.5
else:
belowSize = 0.5 * y[j, i]
below_size = 0.5 * y[j, i]
for k in range(j + 1, m):
belowSize += y[k, i]
below_size += y[k, i]
increase = y[j, i] - y[j, i - 1]
moveUp = belowSize / total[i]
center[i] += (moveUp - 0.5) * increase
move_up = below_size / total[i]
center[i] += (move_up - 0.5) * increase
first_line = center - 0.5 * total
y_stack += first_line
stack += first_line
else:
errstr = "Baseline method %s not recognised. " % baseline
errstr += "Expected 'zero', 'sym', 'wiggle' or 'weighted_wiggle'"
raise ValueError(errstr)

# Color between x = 0 and the first array.
r.append(axes.fill_between(x, first_line, y_stack[0,:],
r.append(axes.fill_between(x, first_line, stack[0, :],
facecolor=axes._get_lines.color_cycle.next(),
**kwargs))

# Color between array i-1 and array i
for i in xrange(len(y)-1):
r.append(axes.fill_between(x, y_stack[i,: ], y_stack[i + 1, :],
facecolor=axes._get_lines.color_cycle.next(),
for i in xrange(len(y) - 1):
color = axes._get_lines.color_cycle.next()
r.append(axes.fill_between(x, stack[i, :], stack[i + 1, :],
facecolor= color,
**kwargs))
return r
Morty Proxy This is a proxified and sanitized view of the page, visit original site.