On a Sample Data,
import pandas as pd
import numpy as np
ranstate = np.random.RandomState(0)
df = pd.DataFrame(ranstate.rand(10, 10))
df[0]=df[0]+df[1]
df[2]=df[0]+df[1]
df[7]=df[9]+df[8]
corr = df.corr()
import networkx as nx
links = corr.stack().reset_index()
links.columns = ['var1', 'var2', 'value']
# Keep only correlation over a threshold and remove self correlation (cor(A,A)=1)
links_filtered=links.loc[ (links['value'] > 0.7) & (links['var1'] != links['var2']) ]
# Build your graph
G=nx.from_pandas_edgelist(links_filtered, 'var1', 'var2')
# Plot the network:
nx.draw(G, with_labels=True, node_color='orange', node_size=400, edge_color='black', linewidths=1, font_size=15)
But with Real Data,
How could I,
- set the Minimum Edge Length so that nodes are readable,
- Annotate The Edge with Correlation Coefficient,
- Color Code the edge [ Light Share to Dark Shade based] based on Correlation Coefficient


