Plot API Example
In [1]:
Copied!
# %pip install phytreeviz
# %pip install phytreeviz
show_branch_length¶
In [2]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.show_branch_length(label_formatter=lambda v: f"{v:.4f}")
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.show_branch_length(label_formatter=lambda v: f"{v:.4f}")
fig = tv.plotfig()
show_confidence¶
In [3]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.show_confidence(ypos="top", label_formatter=lambda v: f"{v:.2f}")
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.show_confidence(ypos="top", label_formatter=lambda v: f"{v:.2f}")
fig = tv.plotfig()
show_scale_axis¶
In [4]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.show_scale_axis(ticks_interval=0.1)
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.show_scale_axis(ticks_interval=0.1)
fig = tv.plotfig()
show_scale_bar¶
In [5]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.show_scale_bar()
tv.show_scale_bar(scale_size=0.1, loc="upper left", label_top=True)
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.show_scale_bar()
tv.show_scale_bar(scale_size=0.1, loc="upper left", label_top=True)
fig = tv.plotfig()
highlight¶
In [6]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.highlight(["Hylobates_moloch", "Nomascus_leucogenys"], "orange", area="branch")
tv.highlight("Pongo_abelii", "pink", area="branch-label")
tv.highlight(["Homo_sapiens", "Pan_paniscus"], "lime", area="full")
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.highlight(["Hylobates_moloch", "Nomascus_leucogenys"], "orange", area="branch")
tv.highlight("Pongo_abelii", "pink", area="branch-label")
tv.highlight(["Homo_sapiens", "Pan_paniscus"], "lime", area="full")
fig = tv.plotfig()
annotate¶
In [7]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.annotate(["Hylobates_moloch", "Nomascus_leucogenys"], "group1", line_color="orange")
tv.annotate("Pongo_abelii", "group2", align=True, line_color="red")
tv.annotate("Gorilla_gorilla_gorilla", "group3", align=True, line_color="blue")
tv.annotate(["Homo_sapiens", "Pan_paniscus"], "group4", line_color="lime", text_orientation="vertical")
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.annotate(["Hylobates_moloch", "Nomascus_leucogenys"], "group1", line_color="orange")
tv.annotate("Pongo_abelii", "group2", align=True, line_color="red")
tv.annotate("Gorilla_gorilla_gorilla", "group3", align=True, line_color="blue")
tv.annotate(["Homo_sapiens", "Pan_paniscus"], "group4", line_color="lime", text_orientation="vertical")
fig = tv.plotfig()
marker¶
In [8]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True, leaf_label_xmargin_ratio=0.02)
tv.marker(["Hylobates_moloch", "Nomascus_leucogenys"], color="blue")
tv.marker("Pongo_abelii", marker="s", color="red")
tv.marker(["Homo_sapiens", "Pan_paniscus"], marker="D", descendent=True, fc="lime", ec="black", lw=0.5)
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True, leaf_label_xmargin_ratio=0.02)
tv.marker(["Hylobates_moloch", "Nomascus_leucogenys"], color="blue")
tv.marker("Pongo_abelii", marker="s", color="red")
tv.marker(["Homo_sapiens", "Pan_paniscus"], marker="D", descendent=True, fc="lime", ec="black", lw=0.5)
fig = tv.plotfig()
link¶
In [9]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.link("Pongo_abelii", ["Hylobates_moloch", "Nomascus_leucogenys"])
tv.link(
"Homo_sapiens",
["Pan_troglodytes", "Pan_paniscus"],
color="blue",
arrowstyle="<|-|>",
connectionstyle="arc3,rad=0.2",
)
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.link("Pongo_abelii", ["Hylobates_moloch", "Nomascus_leucogenys"])
tv.link(
"Homo_sapiens",
["Pan_troglodytes", "Pan_paniscus"],
color="blue",
arrowstyle="<|-|>",
connectionstyle="arc3,rad=0.2",
)
fig = tv.plotfig()
text_on_branch¶
In [10]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.text_on_branch(["Hylobates_moloch", "Nomascus_leucogenys"], text="Node01")
tv.text_on_branch("Pongo_abelii", text="Node02", xpos="left", ypos="bottom", color="red")
tv.text_on_branch(
["Pan_troglodytes", "Pan_paniscus"],
text="Node03",
xpos="center",
ypos="center",
bbox=dict(boxstyle="square,pad=0.3", fc="skyblue")
)
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.text_on_branch(["Hylobates_moloch", "Nomascus_leucogenys"], text="Node01")
tv.text_on_branch("Pongo_abelii", text="Node02", xpos="left", ypos="bottom", color="red")
tv.text_on_branch(
["Pan_troglodytes", "Pan_paniscus"],
text="Node03",
xpos="center",
ypos="center",
bbox=dict(boxstyle="square,pad=0.3", fc="skyblue")
)
fig = tv.plotfig()
text_on_node¶
In [11]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.marker(["Hylobates_moloch", "Nomascus_leucogenys"], fc="lime", ec="black", lw=0.5, size=10)
tv.text_on_node(["Hylobates_moloch", "Nomascus_leucogenys"], "1")
tv.text_on_node(
["Pan_troglodytes", "Pan_paniscus"],
text="Node",
bbox=dict(boxstyle="square,pad=0.3", fc="skyblue")
)
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.marker(["Hylobates_moloch", "Nomascus_leucogenys"], fc="lime", ec="black", lw=0.5, size=10)
tv.text_on_node(["Hylobates_moloch", "Nomascus_leucogenys"], "1")
tv.text_on_node(
["Pan_troglodytes", "Pan_paniscus"],
text="Node",
bbox=dict(boxstyle="square,pad=0.3", fc="skyblue")
)
fig = tv.plotfig()
set_node_label_props¶
In [12]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.set_node_label_props("Hylobates_moloch", color="blue")
tv.set_node_label_props("Pongo_abelii", color="red", style="italic")
tv.set_node_label_props("Homo_sapiens", size=8, backgroundcolor="lime")
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file, align_leaf_label=True)
tv.set_node_label_props("Hylobates_moloch", color="blue")
tv.set_node_label_props("Pongo_abelii", color="red", style="italic")
tv.set_node_label_props("Homo_sapiens", size=8, backgroundcolor="lime")
fig = tv.plotfig()
set_node_line_props¶
In [13]:
Copied!
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.set_node_line_props(["Hylobates_moloch", "Nomascus_leucogenys"], color="orange", lw=2)
tv.set_node_line_props(["Homo_sapiens", "Pan_paniscus"], color="magenta", ls="dotted")
fig = tv.plotfig()
from phytreeviz import TreeViz, load_example_tree_file
tree_file = load_example_tree_file("small_example.nwk")
tv = TreeViz(tree_file)
tv.set_node_line_props(["Hylobates_moloch", "Nomascus_leucogenys"], color="orange", lw=2)
tv.set_node_line_props(["Homo_sapiens", "Pan_paniscus"], color="magenta", ls="dotted")
fig = tv.plotfig()