pik-copan / pyunicorn

Unified Complex Network and Recurrence Analysis Toolbox
http://pik-potsdam.de/~donges/pyunicorn/
Other
195 stars 86 forks source link

Plot a recurrence network (Question) #181

Closed Xorrn closed 1 year ago

Xorrn commented 1 year ago

Hi, I'd like to plot a recurrence network generated with your package (for example the RN in your tutorial). Is there some way to do this? I couldn't find anything about this in the documentation. Thanks!

fkuehlein commented 1 year ago

Hi @Xorrn,

sorry for the delayed response. You can simply plot a pyunicorn.timeseries.RecurrenceNetwork using igraph (which you should have installed already as it is a dependency of pyunicorn). To use it's plotting functionality, you'll have to install pycairo as well.

For a given time_series, just generate an igraph object from the RecurrenceNetwork's adjacency matrix and then plot it. Here's a simple example:

import igraph
import numpy as np
from pyunicorn.timeseries import RecurrenceNetwork

rn = RecurrenceNetwork(time_series, threshold_std=EPS_std)

A = rn.adjacency # get adjacency matrix
n = np.linspace(0, A.shape[0], A.shape[0]+1) # create node numbering

g = igraph.Graph.Adjacency(A.astype(bool).tolist()) # igraph needs A to be a list of booleans 
g.vs['label'] = n # add labels
igraph.plot(g) # plot the network

Hope this helps!