wiheto / teneto

Temporal Network Tools
GNU General Public License v3.0
85 stars 26 forks source link

How to make a community slice plot #84

Closed balandongiv closed 2 years ago

balandongiv commented 2 years ago

Assume we have a temporal network as below.

import numpy as np
import teneto
import matplotlib.pyplot as plt
A1 = np.array ( [[0., 0., 0., 0., 0,0,0],[5., 0., 0., 0., 0,0,0],[1., 0., 0., 0., 0,0,0],
                 [0., 1., 2., 0., 0,0,0],[0., 0., 0., 1., 0,0,0], [0., 0., 0., 1., 0,0,0],
                 [0., 0., 0., 0., 1,1,0]] )

A2 = np.array ( [[0., 0., 0., 0., 0,0,0],[5., 0., 0., 0., 0,0,0], [1., 0., 0., 0., 0,0,0],
                 [0., 1., 2., 0., 0,0,0], [0., 0., 0., 1., 0,0,0],[0., 0., 1., 1., 0,0,0],
                 [0., 0., 0., 0., 1,1,0]] )

A3 = np.array ( [[0., 0., 0., 0., 0,0,0], [0., 0., 0., 0., 0,0,0],[0., 0., 0., 0., 0,0,0],
                 [0., 1., 2., 0., 0,0,0],[0., 0., 0., 1., 0,0,0],[0., 0., 0., 1., 0,0,0],
                 [0., 0., 0., 0., 1,1,0]] )
g_arr=np.array((A1, A2, A3, )).T

tnet = teneto.TemporalNetwork(from_array=g_arr)
ax = tnet.plot('slice_plot')
plt.show()

Picture2

and, assume, we obtain a communities which represented as below

communities = np.array([[0, 0, 0], 
                            [0, 0, 1], 
                            [0, 1, 0], 
                            [0, 0, 0],
                            [1, 1, 0],
                            [0, 0, 2],
                            [0, 0, 2]])

May I know, how to plot these communities to get something as shown in the figure below?

community_plot

In the figure above, let membership 0,1,2 labeled as blue, red and yellow, respectively

one work around I can think of is, by manually adjust the node as

ax.scatter([0,0,0], [0,1,2], s=100, color='red', zorder=100) # along this line of idea

wiheto commented 2 years ago

So it is either:

tnet.plot('slice_plot', **{'communities': communities})

or

teneto.plot.slice_plot(g_arr, ax, communities=communities)

And that should work for you

balandongiv commented 2 years ago

Thanks, this is really helpful