From 4488d7f71952e3b8b0910a4f8dcd46066003e4b8 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Wed, 5 Sep 2018 15:21:19 -0700 Subject: [PATCH] Improving colors and looks of graph plots. --- python_ml/plotting-dbscan-complete.py | 32 +++++++++++++++++---------- python_ml/plotting-dbscan.py | 14 +++++++----- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/python_ml/plotting-dbscan-complete.py b/python_ml/plotting-dbscan-complete.py index d8c015b..55d5af4 100644 --- a/python_ml/plotting-dbscan-complete.py +++ b/python_ml/plotting-dbscan-complete.py @@ -12,9 +12,9 @@ fig.set_size_inches(7, 7) # Read from file # TODO: Just change the following path and filename # when needed to read from a different file -path = "/scratch/July-2018/Pairs/" -device1 = "tplink-bulb-on" -device2 = "tplink-bulb-off" +path = "/scratch/July-2018/Pairs2/" +device1 = "kwikset-on" +device2 = "kwikset-off" filename1 = device1 + ".txt" filename2 = device2 + ".txt" @@ -55,8 +55,8 @@ colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))] for k, col in zip(unique_labels, colors): if k == -1: - # Black used for noise. - col = [0, 0, 0, 1] + # Red used for noise. + col = [1, 0, 0, 1] class_member_mask = (labels == k) @@ -71,8 +71,12 @@ for k, col in zip(unique_labels, colors): count = 0 for pair in pairsArr: - plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]) + - "\nFreq: " + str(labels.tolist().count(labels[count])), fontsize=10) + if labels[count] == -1: + plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]), fontsize=10) + else: + # Only print the frequency when this is a real cluster + plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]) + + "\nFreq: " + str(labels.tolist().count(labels[count])), fontsize=10) count = count + 1 #==================================================================================================== @@ -113,8 +117,8 @@ colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))] for k, col in zip(unique_labels, colors): if k == -1: - # Black used for noise. - col = [0, 0, 0, 1] + # Green used for noise. + col = [0, 1, 0, 1] class_member_mask = (labels == k) @@ -129,13 +133,17 @@ for k, col in zip(unique_labels, colors): count = 0 for pair in pairsArr: - plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]) + - "\nFreq: " + str(labels.tolist().count(labels[count])), fontsize=10) + if labels[count] == -1: + plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]), fontsize=10) + else: + # Only print the frequency when this is a real cluster + plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]) + + "\nFreq: " + str(labels.tolist().count(labels[count])), fontsize=10) count = count + 1 -plt.title(device1 + ' & ' + device2 + ' - Estimated number of clusters: %d' % n_clusters_) +plt.title(device1 + ' & ' + device2) plt.show() diff --git a/python_ml/plotting-dbscan.py b/python_ml/plotting-dbscan.py index 315f0cb..733fe16 100644 --- a/python_ml/plotting-dbscan.py +++ b/python_ml/plotting-dbscan.py @@ -12,8 +12,8 @@ fig.set_size_inches(7, 7) # Read from file # TODO: Just change the following path and filename # when needed to read from a different file -path = "/scratch/July-2018/Pairs/" -device = "dlink-siren-on" +path = "/scratch/July-2018/Pairs2/" +device = "kwikset-off" filename = device + ".txt" # Number of triggers @@ -73,9 +73,13 @@ for pair in pairsArr: #if labels[count] != -1: # If this is not a noise (i.e.,real data) # plt.text(pair[0], pair[1], "Freq: " + str(labels.tolist().count(labels[count])), fontsize=10) - - plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]) + - "\nFreq: " + str(labels.tolist().count(labels[count])), fontsize=10) + + if labels[count] == -1: + plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]), fontsize=10) + else: + # Only print the frequency when this is a real cluster + plt.text(pair[0], pair[1], str(pair[0]) + ", " + str(pair[1]) + + "\nFreq: " + str(labels.tolist().count(labels[count])), fontsize=10) count = count + 1 -- 2.34.1