Creating a graph from a matrix