.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/basic/plot_3d.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_basic_plot_3d.py: 3D layouts ========== This example shows how to visualise graphs or networks in 3D using `iplotx`. Of course, a 3D layout is needed for this. Here, we use the Fruchterman-Reingold layout algorithm from ``igraph`` to generate a 3D layout. .. note:: 3D visualisation is most useful when used **interactively**, so you can rotate and pan the plot to inspect it from different angles. Matplotlib supports this both in Jupyter notebooks and in IPython via multiple interactive backends (e.g., TkAgg, Qt5Agg, etc.). These plots can also be saved as static images (the ones you see below were generated this way), however these static images can be quite difficult to interpret. .. GENERATED FROM PYTHON SOURCE LINES 15-34 .. code-block:: Python import igraph as ig import iplotx as ipx # Make the graph g = ig.Graph.Erdos_Renyi(30, m=50) # Make a 3D layout layout = g.layout_fruchterman_reingold_3d() # Visualise the graph in 3D ipx.network( g, layout, vertex_alpha=0.7, edge_alpha=0.4, figsize=(8, 8), ) .. image-sg:: /gallery/basic/images/sphx_glr_plot_3d_001.png :alt: plot 3d :srcset: /gallery/basic/images/sphx_glr_plot_3d_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 35-36 Below is a variation using arrows and vertex labels: .. GENERATED FROM PYTHON SOURCE LINES 36-56 .. code-block:: Python import igraph as ig import iplotx as ipx # Make the graph g = ig.Graph.Erdos_Renyi(30, m=50, directed=True) # Make a 3D layout layout = g.layout_fruchterman_reingold_3d() # Visualise the graph in 3D ipx.network( g, layout, vertex_alpha=0.3, edge_alpha=0.5, vertex_labels=True, figsize=(8, 8), ) .. image-sg:: /gallery/basic/images/sphx_glr_plot_3d_002.png :alt: plot 3d :srcset: /gallery/basic/images/sphx_glr_plot_3d_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. warning:: 3D visualisation does not support all features of 2D visualisation yet. Curved edges, waypoints, and edge labels are currently unsupported. PRs are welcome! .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.164 seconds) .. _sphx_glr_download_gallery_basic_plot_3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_3d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_3d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_3d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_