From 3276d353aeee7baa861d98e3ae68ac5470c110ca Mon Sep 17 00:00:00 2001 From: roim Date: Mon, 2 Nov 2015 12:00:02 -0200 Subject: [PATCH] Improving clustering plots. --- clustering/kde.py | 2 +- plotting/clustering.py | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/clustering/kde.py b/clustering/kde.py index 81f6048..54cd8c2 100644 --- a/clustering/kde.py +++ b/clustering/kde.py @@ -1,4 +1,4 @@ -# Copyright 2015 Rodrigo Roim Ferreira +# Copyright 2015 Rodrigo Roim Ferreira # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/plotting/clustering.py b/plotting/clustering.py index a1a45f6..19503e5 100644 --- a/plotting/clustering.py +++ b/plotting/clustering.py @@ -1,4 +1,4 @@ -# Copyright 2015 Rodrigo Roim Ferreira +# Copyright 2015 Rodrigo Roim Ferreira # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,11 +18,23 @@ import matplotlib.pyplot as _pl import numpy as _np -import clustering as _clst +import clustering.kde as _kde -# Sample data (Ode to Joy): x = _np.array([5.129283017, 4, 5.044394119, 4, 4, 3.906890596, 4.857980995, 3.906890596, 5.129283017, 5.129283017, 5.087462841, 3.807354922, 5.044394119, 4, 4.087462841, 4, 4.700439718, 3.906890596, 4.087462841, 4, 4.857980995, 4.584962501, 3.906890596, 3.321928095, 3.807354922, 3.807354922, 3.807354922, 4.169925001, 2.807354922, 3.807354922, 3.906890596, 3.906890596, 4.169925001, 3.906890596, 3.700439718, 3.700439718, 5.129283017]) -def plot_kde(x, bw=0.15, bounds=(1,12)): +# Sample data (Ode to Joy): x = _np.log2([20, 23, 21, 23, 23, 22, 24, 22, 22, 20, 22, 22, 34, 10, 44, 21, 21, 21, 23, 23, 22, 25, 22, 50, 22, 22, 33, 10, 50, 21, 21, 20, 25, 22, 10, 11, 25, 25, 22, 10, 10, 24, 22, 25, 22, 26, 44, 23, 20, 22, 22, 21, 20, 11, 10, 50, 22, 24, 33, 11, 53]) +def plot_histogram(x, bounds=(1, 12)): + """Plots a histogram for a given array.""" + plot_width = bounds[1] - bounds[0] + hist_points = _np.linspace(bounds[0], bounds[1], 10*plot_width) + _pl.hist(x, bins=hist_points, range=bounds, fc='gray', histtype='stepfilled', alpha=0.5, normed=False) + + _pl.xlabel("Duração (lg da quantidade de janelas)") + _pl.ylabel("Quantidade de notas") + _pl.show() + return + + +def plot_kde(x, bw=0.15, bounds=(1, 12)): """Plots a histogram and the KDE for a given array.""" plot_width = bounds[1] - bounds[0] @@ -30,7 +42,10 @@ def plot_kde(x, bw=0.15, bounds=(1,12)): _pl.hist(x, bins=hist_points, range=bounds, fc='gray', histtype='stepfilled', alpha=0.5, normed=True) kde_points = _np.linspace(bounds[0], bounds[1], 100*plot_width) - pdf = _clst.kde(x, kde_points, bw) + pdf = _kde.kde(x, kde_points, bw) _pl.plot(kde_points, pdf, color='red', alpha=0.75, lw=2) + _pl.xlabel("Duração (lg da quantidade de janelas)") + _pl.ylabel("Quantidade de notas (normalizada)") _pl.show() + return