In [59]:
%matplotlib inline

from __future__ import division
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt

In [38]:
P = np.array([[0.2, 0.5, 0.2],
             [0, 0.5, 0.5],
             [0, 0, 1]])
G=nx.from_numpy_matrix(P,create_using=nx.MultiDiGraph())

In [55]:
G.edges(data=True)
#pos = nx.random_layout(G)
#nx.draw_networkx_edge_labels(G)
#labels = {i : i + 1 for i in G.nodes()}
labels={}
labels[0]='good'
labels[1]='mediocre'
labels[2]='bad'
nx.draw_networkx_labels(G, pos, labels=labels, font_size=16)
#nx.write_dot(G,'G.dot')


Out[55]:
{0: <matplotlib.text.Text at 0x7fb5359adad0>,
 1: <matplotlib.text.Text at 0x7fb5359ad590>,
 2: <matplotlib.text.Text at 0x7fb535c99f90>}

In [48]:
!neato -T png G.dot > multi.png


In [35]:
dt=[('good',float),('mediocre',float), ('bad', float)]
A=np.matrix([[(0.2, 0.5, 0.2)],
             [(0, 0.5, 0.5)],
             [(0, 0, 1)]], dtype=dt)

In [37]:
G=nx.from_numpy_matrix(A)


---------------------------------------------------------------------------
NetworkXError                             Traceback (most recent call last)
<ipython-input-37-31f5dc21a26a> in <module>()
----> 1 G=nx.from_numpy_matrix(A)

/home/saket/anaconda/lib/python2.7/site-packages/networkx/convert_matrix.pyc in from_numpy_matrix(A, parallel_edges, create_using)
    485     if n!=m:
    486         raise nx.NetworkXError("Adjacency matrix is not square.",
--> 487                                "nx,ny=%s"%(A.shape,))
    488     dt=A.dtype
    489     try:

NetworkXError: ('Adjacency matrix is not square.', 'nx,ny=(3, 1)')

In [1]:


In [5]:




In [6]:
nx.write_dot(G,'G.dot')

In [7]:
!neato -T png G.dot > multi.png


In [ ]:


In [ ]: