.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/tree/plot_angular_waypoints.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_tree_plot_angular_waypoints.py: Angular layout and edge waypoints ================================= This example demonstrates `iplotx`'s capability to style tree appearance with an angular look, either for the whole tree or specific edges. .. tip:: "Waypoints" and "angular" are opposites. When an edge uses waypoints, you can say it is using an angular style. .. GENERATED FROM PYTHON SOURCE LINES 13-49 .. code-block:: Python from Bio import Phylo from io import StringIO import matplotlib.pyplot as plt import iplotx as ipx tree = Phylo.read( StringIO("(((A,B),(C,D)),(E,F,G));"), format="newick", ) fig, axs = plt.subplots(2, 2, figsize=(9, 9)) ipx.tree( tree, ax=axs[0, 0], title="Default\n(with waypoints)", ) ipx.tree( tree, ax=axs[0, 1], layout_angular=True, title="Angular", ) ipx.tree( tree, ax=axs[1, 0], edge_waypoints=False, title="Angular\n(via edge_waypoints)", ) ipx.tree( tree, ax=axs[1, 1], edge_waypoints=[True, False], title="Mixed", ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_angular_waypoints_001.png :alt: Default (with waypoints), Angular, Angular (via edge_waypoints), Mixed :srcset: /gallery/tree/images/sphx_glr_plot_angular_waypoints_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 50-58 .. warning:: For waypoints, ``None`` and the string ``"none"`` are interpreted differently by ``iplotx``. The latter ``"none"`` means no waypoints, whereas the Python singleton ``None`` means letting ``iplotx`` determine the correct type of waypoints. ``None`` is equivalent to ``True``, while ``"none"`` is equivalent to ``False``. You can even specify angularity on a per-edge basis with a defaultdict: .. GENERATED FROM PYTHON SOURCE LINES 58-67 .. code-block:: Python from collections import defaultdict ipx.tree( tree, edge_waypoints=defaultdict(lambda: True, {tree.clade[0, 1]: False}), title="Mixed\n(per-edge)", ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_angular_waypoints_002.png :alt: Mixed (per-edge) :srcset: /gallery/tree/images/sphx_glr_plot_angular_waypoints_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 68-73 .. note:: ``iplotx``'s fallback for per-element styling is the constructor for the **type** used by the first value of the dictionary, in this case ``bool()`` which returns ``False``. Therefore, if we are ok with angular edges as the fallback, we can skip the defaultdict altogether: .. GENERATED FROM PYTHON SOURCE LINES 73-80 .. code-block:: Python ipx.tree( tree, edge_waypoints={tree.clade[0, 1]: True}, title="Mixed per-edge\n(default fallback)", ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_angular_waypoints_003.png :alt: Mixed per-edge (default fallback) :srcset: /gallery/tree/images/sphx_glr_plot_angular_waypoints_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 81-82 You can also mix booleans and other types, although it is not very readable: .. GENERATED FROM PYTHON SOURCE LINES 82-88 .. code-block:: Python ipx.tree( tree, edge_waypoints=[True, "none"], title="Mixed", ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_angular_waypoints_004.png :alt: Mixed :srcset: /gallery/tree/images/sphx_glr_plot_angular_waypoints_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.229 seconds) .. _sphx_glr_download_gallery_tree_plot_angular_waypoints.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_angular_waypoints.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_angular_waypoints.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_angular_waypoints.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_