RDG
RDG

Reputation: 183

Plotting a network using a co-occurrence matrix

I want to plot a network in Python using a co-occurence matrix as an input, such that nodes that have a non-zero co-occurence count are connected, and the weight of the edges is proportional to the number of co-occurrences between each node.

Is there a python library in existence that will facilitate this task using a co-occurence matrix as an input?

Upvotes: 1

Views: 4958

Answers (3)

andrediaslopes
andrediaslopes

Reputation: 1

You can export the information to a graphml file format and use yEd Graph Editor to navigate and format the contents of your networkx graph.

Upvotes: 0

Pedro Borges
Pedro Borges

Reputation: 1270

It is indeed possible to do something like that with networkx

Check this: https://stackoverflow.com/a/25651827/4288795

With it you can generate graphs like this:

enter image description here

Upvotes: 0

yatu
yatu

Reputation: 88236

You might find NetworkX to be a useful tool for that. You can easily feed it the input nodes and edges in several ways.

In the case that you want to generate your network using a co-occurrence matrix, you can use NetworkX's method from_numpy_matrix, which allows you to create a graph from a numpy matrix matrix which will be interpreted as an adjacency matrix.

Here's a simply toy example from the documentation:

import numpy as np
import networkx as nx

A=np.matrix([[1,1],[2,1]])
G=nx.from_numpy_matrix(A)

Upvotes: 2

Related Questions