A community-maintained Python framework for creating mathematical animations.
New example to graph.py documentation (#2851)
Pedro Lamkowski8dd88606e048
diff --git a/manim/mobject/graph.py b/manim/mobject/graph.pyindex 20d430a5a..2f24bbbf2 100644--- a/manim/mobject/graph.py+++ b/manim/mobject/graph.py@@ -382,6 +382,40 @@ class Graph(VMobject, metaclass=ConvertToOpenGL):graph = Graph(list(G.nodes), list(G.edges), layout="partite", partitions=[[0, 1]])self.play(Create(graph))+ The representation of a linear artificial neural network is facilitated+ by the use of the partite layout and defining partitions for each layer.++ .. manim:: LinearNN+ :save_last_frame:++ class LinearNN(Scene):+ def construct(self):+ edges = []+ partitions = []+ c = 0+ layers = [2, 3, 3, 2] # the number of neurons in each layer++ for i in layers:+ partitions.append(list(range(c + 1, c + i + 1)))+ c += i+ for i, v in enumerate(layers[1:]):+ last = sum(layers[:i+1])+ for j in range(v):+ for k in range(last - layers[i], last):+ edges.append((k + 1, j + last + 1))++ vertices = np.arange(1, sum(layers) + 1)++ graph = Graph(+ vertices,+ edges,+ layout='partite',+ partitions=partitions,+ layout_scale=3,+ vertex_config={'radius': 0.20},+ )+ self.add(graph)+The custom tree layout can be used to show the graphby distance from the root vertex. You must pass the root vertexof the tree.