Skip to content

Instantly share code, notes, and snippets.

@egpbos
Created May 8, 2016 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egpbos/2b7f9c2dfbd83bbdb2f977ea77f3e189 to your computer and use it in GitHub Desktop.
Save egpbos/2b7f9c2dfbd83bbdb2f977ea77f3e189 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
def remove_text(figure):
figure.suptitle("")
for ax in figure.get_axes():
ax.set_title("")
ax.xaxis.set_major_formatter(mpl.ticker.NullFormatter())
ax.xaxis.set_minor_formatter(mpl.ticker.NullFormatter())
ax.yaxis.set_major_formatter(mpl.ticker.NullFormatter())
ax.yaxis.set_minor_formatter(mpl.ticker.NullFormatter())
try:
ax.zaxis.set_major_formatter(mpl.ticker.NullFormatter())
ax.zaxis.set_minor_formatter(mpl.ticker.NullFormatter())
except AttributeError:
pass
def test_stackplot_baseline():
np.random.seed(0)
def layers(n, 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)
d[50,:] = 0 # test for fixed weighted wiggle (issue #6313)
fig = plt.figure()
plt.subplot(2, 2, 1)
plt.stackplot(list(xrange(100)), d.T, baseline='zero')
plt.subplot(2, 2, 2)
plt.stackplot(list(xrange(100)), d.T, baseline='sym')
plt.subplot(2, 2, 3)
plt.stackplot(list(xrange(100)), d.T, baseline='wiggle')
plt.subplot(2, 2, 4)
plt.stackplot(list(xrange(100)), d.T, baseline='weighted_wiggle')
remove_text(fig)
plt.savefig('stackplot_test_baseline.png')
plt.savefig('stackplot_test_baseline.pdf')
plt.savefig('stackplot_test_baseline.svg')
test_stackplot_baseline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment