.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/tree/plot_double_tree.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_double_tree.py: Double tree =========== This example shows how to use `iplotx` to plot two trees facing each other, which is typical in coevolutionary studies. .. GENERATED FROM PYTHON SOURCE LINES 7-58 .. code-block:: Python from ete4 import Tree from matplotlib import pyplot as plt import iplotx as ipx tree1 = Tree( "((),((),(((),()),((),()))));", ) tree2 = Tree( "((),((),(),((),())),());", ) fig, ax = plt.subplots(figsize=(9, 4)) # Plot first tree on the left ipx.plotting.tree( tree1, ax=ax, aspect=1, edge_color="tomato", leaf_deep=True, ) # Plot second tree on the right, facing left ipx.plotting.tree( tree2, ax=ax, aspect=1, edge_color="steelblue", layout="horizontal", layout_orientation="left", layout_start=(11, 0), leaf_deep=True, ) # Add lines connecting corresponding leaves matches = [ (0, 0), (1, 4), (2, 5), (3, 2), (4, 1), (5, 5), ] for y1, y2 in matches: ax.plot( [5.2, 6.8], [y1, y2], color="gray", linewidth=2, ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_double_tree_001.png :alt: plot double tree :srcset: /gallery/tree/images/sphx_glr_plot_double_tree_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 59-60 ``iplotx`` has a dedicated function for double trees, which virtually the same result with less code: .. GENERATED FROM PYTHON SOURCE LINES 60-92 .. code-block:: Python fig, ax = plt.subplots(figsize=(9, 4)) ipx.doubletree( tree1, tree2, ax=ax, kwargs_left=dict( leaf_deep=True, edge_color="tomato", ), kwargs_right=dict( leaf_deep=True, edge_color="steelblue", ), gap=2, aspect=1, ) # Add lines connecting corresponding leaves # NOTE: The layout is horizontally centered now matches = [ (0, 0), (1, 4), (2, 5), (3, 2), (4, 1), (5, 5), ] for y1, y2 in matches: ax.plot( [-0.3, 1.3], [y1, y2], color="gray", linewidth=2, ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_double_tree_002.png :alt: plot double tree :srcset: /gallery/tree/images/sphx_glr_plot_double_tree_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.129 seconds) .. _sphx_glr_download_gallery_tree_plot_double_tree.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_double_tree.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_double_tree.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_double_tree.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_