Generating graph from distance matrix using networkx: inconsistency - Python
<p>I have the following distance matrix:</p>

<pre><code>delta =
[[ 0.          0.71370845  0.80903791  0.82955157  0.56964983  0.          0.        ]
 [ 0.71370845  0.          0.99583115  1.          0.79563006  0.71370845
   0.71370845]
 [ 0.80903791  0.99583115  0.          0.90029133  0.81180111  0.80903791
   0.80903791]
 [ 0.82955157  1.          0.90029133  0.          0.97468433  0.82955157
   0.82955157]
 [ 0.56964983  0.79563006  0.81180111  0.97468433  0.          0.56964983
   0.56964983]
 [ 0.          0.71370845  0.80903791  0.82955157  0.56964983  0.          0.        ]
 [ 0.          0.71370845  0.80903791  0.82955157  0.56964983  0.          0.        ]]
</code></pre>

<p>And I'm trying to use the networkx library to represent it as a graph.
This is my code:</p>

<pre><code>import networkx as nx

G = nx.from_numpy_matrix(delta) 
pos = nx.random_layout(G) 

plt.figure(figsize=(7, 7))
for k, p in pos.iteritems():
    plt.scatter(p[0], p[1], marker='o', c=colors[k], s=50, edgecolor='None')
lgd = plt.legend(markers, labels, numpoints=1, bbox_to_anchor=(1.17, 0.5))
plt.tight_layout()
plt.axis('equal')
pt.show()
</code></pre>

<p>However, what I see is not what I expect. For instance, consider this output:</p>

<p><a href="https://i.stack.imgur.com/e26FP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e26FP.png" alt="enter image description here"></a></p>

<p>From <code>delta</code>, node 1 is at the same point as node 6 and 7, and far from node 4. I don't see the in the output plot. Besides, overtime I run it, it results in another output. This is expected, but the distance seem to not be respected. In the following plot, for example, distances between 1 to 6,7 and 4 changed.</p>

<p><a href="https://i.stack.imgur.com/bKsjX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bKsjX.png" alt="enter image description here"></a></p>

<p>I can't understand why.</p>