springer-math / Mathematics-of-Epidemics-on-Networks

Source code accompanying 'Mathematics of Epidemics on Networks' by Kiss, Miller, and Simon http://www.springer.com/us/book/9783319508047 . Documentation for the software package is at https://epidemicsonnetworks.readthedocs.io/en/latest/
MIT License
151 stars 61 forks source link

Plot animation with a graph from matrix #52

Closed atilaajones closed 4 years ago

atilaajones commented 4 years ago

Hello. How can I use save and animation package with a simple graph created from adjacency matrix? In the EoN page, there is a example with a graph Grid2D, but when I trie with a graph from adjacency matrix I received the error: vertices' must be a 2d list or array with shape nx2

Bellow I write part of my code:

A = np.matrix(np.matrix(pd.read_excel(os.path.abspath("teste")))) 
G = nx.from_numpy_matrix(A)
pos = {node:node for node in G}
sim_kwargs = {'pos': pos}
sim = EoN.fast_SIR(G, 2.0, 1.0, initial_infecteds = initial_infections,
               tmax = 40, return_full_data=True, sim_kwargs = sim_kwargs)

ani=sim.animate(ts_plots=['I', 'SIR'], node_size = 4)
ani.save('SIR_2dgrid.mp4', fps=5, extra_args=['-vcodec', 'libx264'])
joelmiller commented 4 years ago

Hello,

It's not clear to me where the error is occuring. Can you tell me what line it's happening in? Also it is likely to help if I know what version of numpy and matplotlib you have.

atilaajones commented 4 years ago

The error was the lack of installation of a package related to '-vcodec', 'libx264'. Thank you very much for your attention to my problem.

joelmiller commented 4 years ago

Great - glad to hear it's resolved.

Please come back if other issues arise.