In [1]:
# this is some code
In [ ]:
$f(x~|~\theta) = y$
In [2]:
import json
import matplotlib.pyplot as plt
import mpld3
%matplotlib inline
mpld3.enable_notebook()
In [3]:
plt.plot(range(10), range(10))
Out[3]:
In [4]:
data = json.load(open("stats-1.json"))
In [8]:
data[0], data[0]['pitches'].values()
Out[8]:
In [9]:
# Filter out pitch counts that are probably corrupt
data = [x for x in data if sum(x['pitches'].values()) > 1]
In [10]:
len(data)
Out[10]:
In [12]:
import numpy as np
In [117]:
def compute_meta(item):
diatonics = np.array([0, 2, 4, 5, 7, 9, 11])
non_diatonics = np.array([1, 3, 6, 8, 10])
# Turn the pitch counts into an array
pitches = np.array([item['pitches'][str(p)] for p in range(12)])
# Guess the tonic based on energy, returns an int
tonic = np.argmax(pitches)
# Sum diatonic energy
dia_energy = pitches[(tonic + diatonics) % 12].mean()
nondia_energy = pitches[(tonic + non_diatonics) % 12].mean()
return dia_energy, nondia_energy
In [118]:
compute_meta(data[0])
Out[118]:
In [119]:
coords = np.array([compute_meta(x) for x in data])
names = [x['name'] for x in data]
In [120]:
coords.shape, len(names)
Out[120]:
In [121]:
from mpld3 import plugins
In [122]:
fig, ax = plt.subplots(figsize=(10, 10))
idx = np.random.permutation(len(coords))[:100]
points = ax.plot(coords[idx, 0], coords[idx, 1], 'o', color='b',
mec='k', ms=15, mew=1, alpha=.6)
ax.set_xlabel('diatonic')
ax.set_ylabel('non-diatonic')
ax.set_title('Diatonic Ratios', size=20)
tooltip = plugins.PointHTMLTooltip(points[0], names,
voffset=10, hoffset=10)
plugins.connect(fig, tooltip)
plt.show()
In [ ]:
In [ ]: