3
$\begingroup$

I'm struggling because while I want to show the interrelationship of correlation between my fields, I realize that trying to plot nodes in terms of distance away from each other based on correlation will lead to impossibilities such as a case where A and B are 1 unit apart, B and C are 1 unit apart, but C and A are say, 5 units apart, there is no way to represent this on a 2 dimensional plane.

I simply want to create a visualization that generally clusters things with high correlation together, and moves things that are anti-correlated apart. So far, the closest I've gotten is using python networkx:

import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()

for ii in range(len(links_filtered)):
    a = data['var1'][ii]
    b = data['var2'][ii]
    c = data['value'][ii]
    G.add_edge(a,b,length=c,weight=c)

elarge = [(u,v) for (u,v,d) in G.edges(data=True) if d['weight']>0]
esmall = [(u,v) for (u,v,d) in G.edges(data=True) if d['weight']<=0]

pos = nx.spring_layout(G,k=.2,iterations=10000)

nx.draw_networkx_nodes(G,pos,node_color='orange',node_size=400)
nx.draw_networkx_edges(G,pos,edgelist=elarge,edge_color='blue')
nx.draw_networkx_edges(G,pos,edgelist=esmall,edge_color='red',alpha=0.5,style='dashed')
# nx.draw_networkx_labels(G,pos,font_size=8,)

for k,v in pos.iteritems():
    x,y = pos[k]
    plt.text(x,y,k,bbox=dict(facecolor='white',alpha=0.8),horizontalalignment='center',verticalalignment='baseline',fontsize=8,color='black')

However, the result is generally ugly, and doesn't actually ensure that clusters that are not correlated are not in close proximity, since it is only drawing edges, not actually calcing a distance between nodes.enter image description here

$\endgroup$

closed as unclear what you're asking by mkt, Peter Flom Jun 21 at 12:39

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ I see a few off-topic close votes, but I think there is an interesting data viz question here if you take away the Python aspect: is there a good way to visualize correlation as a node graph? $\endgroup$ – xan Jan 19 '18 at 16:21
  • $\begingroup$ This is too subjective to opinion, I suggest narrowing down the question a bit further. $\endgroup$ – Firebug Feb 18 '18 at 15:29