You are reading an old version of the documentation (v1.5.3). For the latest version see

Matplotlib 2.0.0rc2 is available

Install the release candidate now!



This Page

pylab_examples example code: stackplot_demo2.pyΒΆ

(Source code, png, hires.png, pdf)

import numpy as np
import matplotlib.pyplot as plt


def layers(n, m):
    Return *n* random Gaussian mixtures, each of length *m*.
    def bump(a):
        x = 1 / (.1 + np.random.random())
        y = 2 * np.random.random() - .5
        z = 10 / (.1 + np.random.random())
        for i in range(m):
            w = (i / float(m) - y) * z
            a[i] += x * np.exp(-w * w)
    a = np.zeros((m, n))
    for i in range(n):
        for j in range(5):
            bump(a[:, i])
    return a

d = layers(3, 100)

plt.stackplot(range(100), d.T, baseline='wiggle')

Keywords: python, matplotlib, pylab, example, codex (see Search examples)