1

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?

1
  • 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. Commented Apr 25, 2017 at 19:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The Netowkx documentation 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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.