0

I have an adjacency matrix that I want to clearly generate a graphical view (a directed graph) showing all the nodes and edges using Python-- I found a similar question that was solved in Matlab.

I was able to find a solution using Pandas and Networkx but there is a limitation that I could not solve.

See the following code I used to generate the graph in Jupyter Notebook:

%matplotlib inline

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

mx = pd.read_csv('/Users/student/Desktop/matrix.csv', sep='\t')
G  = nx.DiGraph(mx.values)
nx.draw_networks(G)

This is output graph:

enter image description here

Problem: the graph is too small and I cannot see all the nodes clearly because the x-axis and y-axis is limited to 1.0.

I am having difficulty writing the scripts that expands the range of the axes in this matplotlib graph? I also want to mention that DiGraph() has ax parameter that take Matplotlib Axes object

Could help me how to solve this problem?

Community
  • 1
  • 1
MEhsan
  • 2,184
  • 9
  • 27
  • 41
  • It's not so much the range of the axes. You can scale them up, and the plot will still basically look the same. You'll want to play around with the different layouts that networkx provides. Even still it may be very hard. However given the lack of edges crossing the middle of your circle, I think there's a reasonable chance of success. – Joel Apr 25 '17 at 19:16

1 Answers1

0

On the on

nx.draw_networks(G)

there are no parameters. In the networkx documentation pages there are many different ways to draw a graph using different methods to show nodes and arcs.

Networks can be difficult to visualize and experimentation with different display functions may be needed to find the one that works for any given data-set.

Darrell Ulm
  • 132
  • 1
  • 2
  • 11
  • The [Netowkx documentation](https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.drawing.nx_pylab.draw_networkx.html) states `.draw_networks(G, )` has the parameter `ax`, which takes a `Matplotlib Axes object`,but I do not know how to use it in my code – MEhsan Apr 25 '17 at 19:14
  • Adjusting the axes won't help with the problems you're having. You need to use a different layout. Look at the options networkx has for different layouts. – Joel Apr 26 '17 at 03:27