Skip to content

Instantly share code, notes, and snippets.

@npyoung
Created February 24, 2022 23:45
Show Gist options
  • Save npyoung/50e00548e63a1e900e68cbde43784d0d to your computer and use it in GitHub Desktop.
Save npyoung/50e00548e63a1e900e68cbde43784d0d to your computer and use it in GitHub Desktop.
Apply Joy Division to your timeseries data
import numpy as np
from scipy.signal.windows import hamming
class Joy:
def __truediv__(cls, arr):
T, N = arr.shape
spacer = 2 * np.arange(N)
t = np.arange(T)
window = hamming(T)
normed = (arr - arr.mean(0)) / (1e-3 + arr.std(0))
fig = plt.figure(figsize=(6, 8), facecolor='k')
for n in range(N):
plt.plot(t, win * normed[:,n] + spacer[n], lw=1, c='0.9', zorder=2*(N-n))
plt.fill_between(x=t, y1=win * normed[:,n] + spacer[n], y2=(win*normed[:,n]).min() + spacer[n], color='k', lw=0, zorder=2*(N-n)+1)
plt.axis('off')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment