.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "sphinx_gallery_animations/plot_03_animate_nodes.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_03_animate_nodes.py: Visualise Changes in Node Properties ==================================== Here, we visualise changes in the nodes of a network. We change both, the colour and the size of the nodes. .. GENERATED FROM PYTHON SOURCE LINES 9-43 .. 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 / different node states, # - with 10 nodes at each time point, and # - an expected edge density of 25%. total_frames = 5 total_nodes = 10 adjacency_matrix = np.random.rand(total_nodes, total_nodes) < 0.25 node_values = np.random.rand(total_frames, total_nodes) cmap = plt.cm.viridis fig, ax = plt.subplots() g = Graph(adjacency_matrix, edge_width=1.5, arrows=True, ax=ax) ax.axis([0, 1, 0, 1]) def update(ii): for node, artist in g.node_artists.items(): value = node_values[ii, node] artist.set_facecolor(cmap(value)) artist.set_edgecolor(cmap(value)) # The default node size is 3., which is rescaled internally # to 0.03 to yield layouts comparable to networkx and igraph. # As the expectation of `value` is 0.5, we multiply `value` by 6 * 0.01, # and thus match the default node size on average. artist.radius = 6 * 0.01 * value return g.node_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.166 seconds) .. _sphx_glr_download_sphinx_gallery_animations_plot_03_animate_nodes.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_03_animate_nodes.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_animate_nodes.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_