.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/fun/plot_train.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_fun_plot_train.py: Train tracks ============ This example demonstrates how to visualise train tracks using ``iplotx``. The layout, ports, edges, and colors are crafted by hand, as you would expect for such a bespoke diagram. .. GENERATED FROM PYTHON SOURCE LINES 10-98 .. image-sg:: /gallery/fun/images/sphx_glr_plot_train_001.png :alt: plot train :srcset: /gallery/fun/images/sphx_glr_plot_train_001.png :class: sphx-glr-single-img .. code-block:: Python import igraph as ig import numpy as np import pandas as pd import matplotlib.pyplot as plt import iplotx as ipx edges = [ (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (6, 7), (7, 2), (2, 8), (8, 9), (9, 10), (10, 11), (12, 13), (13, 4), (4, 14), (14, 15), ] g = ig.Graph(edges, directed=False) layout = np.array([ [0, 0], [1, 0], [2, 1], [2, 3], [2, 5], [1, 7], [5, 1], [4, 1], [0, 1], [0, 2], [3, 2], [5, 3], [4, 6], [4, 5], [0, 5], [-1, 4], ], dtype=float) # Use edge ports to control the train tracks placement between stations ports_dict = { (1, 2): ("e", "s"), (4, 5): ("n", "se"), (8, 9): ("w", "w"), (10, 11): ("e", "sw"), (14, 15): ("w", "n"), } ports = [ports_dict.get(edge, None) for edge in edges] tension = [0.5 * int(port is not None) for port in ports] # Color stations and tracks by line edge_color = ["tomato"] * 5 + ["steelblue"] * 6 + ["darkseagreen"] * 4 vertex_color = ["tomato"] * 6 + ["steelblue"] * 6 + ["darkseagreen"] * 4 # Hub stations are black vertex_color[2] = "black" vertex_color[4] = "black" # Visualise fig, ax = plt.subplots(figsize=(7, 7)) ipx.network( g, layout=layout, ax=ax, edge_ports=ports, edge_curved=True, edge_tension=tension, aspect="equal", vertex_labels=True, edge_linewidth=4, vertex_linewidth=4, vertex_facecolor="white", vertex_label_color="black", vertex_edgecolor=vertex_color, edge_color=edge_color, edge_capstyle="butt", vertex_zorder=3, ) fig.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.067 seconds) .. _sphx_glr_download_gallery_fun_plot_train.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_train.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_train.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_train.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_