Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132923 views
License: OTHER
1
from imageio import imread
2
import matplotlib.pyplot as plt
3
4
5
def plot_animal_tree(ax=None):
6
import graphviz
7
if ax is None:
8
ax = plt.gca()
9
mygraph = graphviz.Digraph(node_attr={'shape': 'box'},
10
edge_attr={'labeldistance': "10.5"},
11
format="png")
12
mygraph.node("0", "Has feathers?")
13
mygraph.node("1", "Can fly?")
14
mygraph.node("2", "Has fins?")
15
mygraph.node("3", "Hawk")
16
mygraph.node("4", "Penguin")
17
mygraph.node("5", "Dolphin")
18
mygraph.node("6", "Bear")
19
mygraph.edge("0", "1", label="True")
20
mygraph.edge("0", "2", label="False")
21
mygraph.edge("1", "3", label="True")
22
mygraph.edge("1", "4", label="False")
23
mygraph.edge("2", "5", label="True")
24
mygraph.edge("2", "6", label="False")
25
mygraph.render("tmp")
26
ax.imshow(imread("tmp.png"))
27
ax.set_axis_off()
28
29