Skip to content

Instantly share code, notes, and snippets.

@monochromegane
Created February 25, 2018 11:25
Show Gist options
  • Save monochromegane/8b6a2a18084297e05f3d25bde2518a9c to your computer and use it in GitHub Desktop.
Save monochromegane/8b6a2a18084297e05f3d25bde2518a9c to your computer and use it in GitHub Desktop.
Plotting outliers script called by https://github.com/monochromegane/smartsifter example.
import os
import numpy as np
import matplotlib.pyplot as plt
def plot(f, points):
n = int(f.split('_')[1].split('.')[0])
size = 100
scores = np.loadtxt("tmp/{}".format(f), delimiter=",").reshape(size, size)
xs = np.linspace(-2.5, 2.5, size, endpoint=False)
ys = np.linspace(-2.5, 2.5, size, endpoint=False)
plt.figure(figsize=(3.25,2.25))
plt.title('Online outlier by SmartSifter')
plt.pcolor(xs, ys, scores, vmin=0.0, vmax=15.0)
plt.colorbar()
plt.scatter(points[0:n:,0], points[0:n,1])
plt.savefig("out/{0:03d}.jpg".format(n))
def load_data(f):
points = np.loadtxt(f, delimiter=",")
x = points[:,0]
y = points[:,1]
x = (x - x.mean()) / x.std()
y = (y - y.mean()) / y.std()
return np.dstack((x, y))[0]
points = load_data('faithful.csv')
if not os.path.exists('out'):
os.mkdir('out')
for i, f in enumerate(os.listdir('tmp')):
if i%4 == 0:
plot(f, points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment