.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "sphinx_gallery_animations/plot_01_dynamic_network.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_sphinx_gallery_animations_plot_01_dynamic_network.py: Visualise Changes in Connectivity ================================= Here, we demonstrate how to visualise changes in connectivity over time. .. GENERATED FROM PYTHON SOURCE LINES 8-35 .. container:: sphx-glr-animation .. raw:: html
.. code-block:: default import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation from netgraph import Graph # Simulate a dynamic network with # - 5 frames / network states, # - with 10 nodes at each time point, # - an expected edge density of 25% at each time point total_frames = 5 total_nodes = 10 adjacency_matrix = np.random.rand(total_frames, total_nodes, total_nodes) < 0.25 fig, ax = plt.subplots() g = Graph(np.ones((total_nodes, total_nodes)), edge_width=1.5, arrows=True, ax=ax) # initialise with fully connected graph def update(ii): for (jj, kk), artist in g.edge_artists.items(): # turn visibility of edge artists on or off, depending on the adjacency if adjacency_matrix[ii, jj, kk]: artist.set_visible(True) else: artist.set_visible(False) return g.edge_artists.values() animation = FuncAnimation(fig, update, frames=total_frames, interval=200, blit=True) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.236 seconds) .. _sphx_glr_download_sphinx_gallery_animations_plot_01_dynamic_network.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_dynamic_network.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_dynamic_network.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_