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

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates



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)