.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/network_science/plot_arrowlawn.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_network_science_plot_arrowlawn.py: Arrow lawn ========== This example demonstrates the visualisation of a network with 1,000 nodes and a few thousand edges, using a custom layout that resembles a lawn of arrows. .. GENERATED FROM PYTHON SOURCE LINES 8-46 .. code-block:: Python import numpy as np import iplotx as ipx import matplotlib.pyplot as plt n = 1000 # Number of nodes k = 3 layout = np.random.rand(n, 2) nodes = np.arange(n) edges = [] for i, v1 in enumerate(layout): found = 0 dv = layout - v1 for j in (dv**2).sum(axis=1).argsort()[1:]: angle = 180 / np.pi * np.arctan2(dv[j, 1], dv[j, 0]) # Only make an edge for neighbors towards the north-east if 10 < angle < 80: edges.append((i, j)) found += 1 if found == k: break # Plot the network using iplotx fig, ax = plt.subplots(figsize=(7, 7)) ipx.network( {'nodes': nodes, 'edges': edges, 'directed': True}, layout=layout, ax=ax, vertex_size=5, vertex_alpha=0.8, vertex_facecolor="seagreen", vertex_edgecolor="none", edge_arrow_width=3, edge_alpha=0.5, ) fig.tight_layout() .. image-sg:: /gallery/network_science/images/sphx_glr_plot_arrowlawn_001.png :alt: plot arrowlawn :srcset: /gallery/network_science/images/sphx_glr_plot_arrowlawn_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-50 If you want to start pushing the scalability of iplotx, you can try with 10,000 nodes and ~30,000 edges. This takes ~14 seconds on a modern laptop, of which 5 are spent on building the network and 9 are spent inside of ``iplotx`` visualising it: .. GENERATED FROM PYTHON SOURCE LINES 50-82 .. code-block:: Python n = 10000 # Number of nodes k = 3 layout = np.random.rand(n, 2) nodes = np.arange(n) edges = [] for i, v1 in enumerate(layout): found = 0 dv = layout - v1 for j in (dv**2).sum(axis=1).argsort()[1:]: angle = 180 / np.pi * np.arctan2(dv[j, 1], dv[j, 0]) # Only make an edge for neighbors towards the north-east if 10 < angle < 80: edges.append((i, j)) found += 1 if found == k: break # Plot the network using iplotx fig, ax = plt.subplots(figsize=(9, 9)) ipx.network( {'nodes': nodes, 'edges': edges, 'directed': True}, layout=layout, ax=ax, vertex_size=5, vertex_alpha=0.8, vertex_facecolor="seagreen", vertex_edgecolor="none", edge_arrow_width=3, edge_alpha=0.5, ) fig.tight_layout() .. image-sg:: /gallery/network_science/images/sphx_glr_plot_arrowlawn_002.png :alt: plot arrowlawn :srcset: /gallery/network_science/images/sphx_glr_plot_arrowlawn_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 49.499 seconds) .. _sphx_glr_download_gallery_network_science_plot_arrowlawn.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_arrowlawn.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_arrowlawn.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_arrowlawn.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_