# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Plots of week 5
# For Girvan-Newman, K-Means, and Hierarchical clustering

from utils import hc_cluster_score, km_cluster_score, d_mat, comm_auto
import networkx as nx
from os import listdir, chdir
from os.path import isfile, join
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

mypath = '../raccoon_proximity_weighted'
files = [mypath + '/' + f for f in listdir(mypath) if isfile(join(mypath, f))]
files = [(int(f.split('_')[5].split('.')[0]), f) for f in files]
files.sort()
filt = [str(x) for x in range(16)]

#Read 5th week and create a position csv
G = nx.read_graphml(files[4][1]).subgraph(filt)
cl1, sc1 = hc_cluster_score(d_mat(G), G)

cl2, sc2 = km_cluster_score(d_mat(G), G)

cl3 = list(comm_auto(G, d_mat(G)).values())

# +
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1, figsize=(4, 12))
#Plot week 5 with cluster color
p = pd.read_csv('pos_w5.csv', index_col=0)
p.index = p.index.map(str)
p = dict(p.apply(lambda x: np.array([x[0], x[1]]), axis=1))

nx.draw_networkx_nodes(G, p, node_color=list(cl1.values()), node_size=500, label=G.nodes(), ax=ax1)
nx.draw_networkx_edges(G, p, alpha=0.2, ax=ax1)

nx.draw_networkx_nodes(G, p, node_color=list(cl2.values()), node_size=500, label=G.nodes(), ax=ax2)
nx.draw_networkx_edges(G, p, alpha=0.2, ax=ax2)

nx.draw_networkx_nodes(G, p, node_color=cl3, node_size=500, label=G.nodes(), ax=ax3)
nx.draw_networkx_edges(G, p, alpha=0.2, ax=ax3)

ax1.axis('off')
ax2.axis('off')
ax3.axis('off')

ax1.set_title('HC of week 5', size=14)
ax2.set_title('K-M of week 5', size=14)
ax3.set_title('Commmunities of week 5', size=14)

plt.show()

# +
fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(12, 4))
#Plot week 5 with cluster color
p = pd.read_csv('pos_w5.csv', index_col=0)
p.index = p.index.map(str)
p = dict(p.apply(lambda x: np.array([x[0], x[1]]), axis=1))

nx.draw_networkx_nodes(G, p, node_color=list(cl1.values()), node_size=500, label=G.nodes(), ax=ax1)
nx.draw_networkx_edges(G, p, alpha=0.2, ax=ax1)

nx.draw_networkx_nodes(G, p, node_color=list(cl2.values()), node_size=500, label=G.nodes(), ax=ax2)
nx.draw_networkx_edges(G, p, alpha=0.2, ax=ax2)

nx.draw_networkx_nodes(G, p, node_color=cl3, node_size=500, label=G.nodes(), ax=ax3)
nx.draw_networkx_edges(G, p, alpha=0.2, ax=ax3)

ax1.axis('off')
ax2.axis('off')
ax3.axis('off')

ax1.set_title('HC of week 5', size=14)
ax2.set_title('K-M of week 5', size=14)
ax3.set_title('Commmunities of week 5', size=14)

plt.show()
# -



StarcoderdataJupyterScriptsDedupFiltered