.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/tree/plot_cogent3_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_cogent3_tree.py: Cogent3 tree ============== This example shows how to use `iplotx` to plot trees from `cogent3`, the successor to `pycogent`. .. GENERATED FROM PYTHON SOURCE LINES 7-23 .. code-block:: Python from cogent3.phylo import nj import numpy as np import iplotx as ipx import matplotlib.pyplot as plt nleaves = 8 distance_dict = {} for i in range(nleaves): for j in range(i): distance_dict[(str(i), str(j))] = np.random.rand() tree = nj.nj(distance_dict) ipx.plotting.tree( tree, ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_cogent3_tree_001.png :alt: plot cogent3 tree :srcset: /gallery/tree/images/sphx_glr_plot_cogent3_tree_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 24-27 To add labels to the leaves, you can use the `vertex_labels` argument as a dictionary. Moreover, the plot can be customised further using hmargin (horizontal label margin) and some `matplotlib` settings. .. GENERATED FROM PYTHON SOURCE LINES 27-38 .. code-block:: Python leaf_labels = {leaf: f"Species {i + 1}" for i, leaf in enumerate(tree.tips())} fig, ax = plt.subplots(figsize=(5, 4)) ipx.plotting.tree( tree, ax=ax, vertex_labels=leaf_labels, vertex_label_hmargin=10, ) ax.set_xlim(-0.2, 1.5) .. image-sg:: /gallery/tree/images/sphx_glr_plot_cogent3_tree_002.png :alt: plot cogent3 tree :srcset: /gallery/tree/images/sphx_glr_plot_cogent3_tree_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (-0.2, 1.5) .. GENERATED FROM PYTHON SOURCE LINES 39-41 `iplotx` can compute a radial tree layout as well, and usual style modifications work for trees same as networks: .. GENERATED FROM PYTHON SOURCE LINES 41-56 .. code-block:: Python ipx.plotting.tree( tree, layout="radial", style=[ "tree", { "edge": { "color": "deeppink", "linewidth": 4, }, }, ], aspect=1, ) .. image-sg:: /gallery/tree/images/sphx_glr_plot_cogent3_tree_003.png :alt: plot cogent3 tree :srcset: /gallery/tree/images/sphx_glr_plot_cogent3_tree_003.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.114 seconds) .. _sphx_glr_download_gallery_tree_plot_cogent3_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_cogent3_tree.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_cogent3_tree.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_cogent3_tree.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_