Groups¶
The film's code
import manimgx as m
class GroupsHero(m.Scene):
def construct(self) -> None:
shapes = m.VGroup(
m.Circle(color=m.BLUE, fill_opacity=0.5),
m.Square(color=m.GREEN, fill_opacity=0.5),
m.Triangle(color=m.YELLOW, fill_opacity=0.5),
m.Star(color=m.RED, fill_opacity=0.5),
)
shapes.arrange(buff=0.6)
self.play(m.LaggedStart(*[m.Create(shape) for shape in shapes], lag_ratio=0.2))
self.play(shapes.animate.arrange_in_grid(rows=2, buff=0.6))
self.play(shapes.animate.arrange(m.DOWN, buff=0.3).scale(0.6))
self.play(shapes.animate.set_color(m.TEAL))
self.wait()
A mobject can hold other mobjects, its parts. A group holds nothing else: its parts are what it shows. Move, scale, color or animate a group, and every part changes with it.
m.VGroup and m.Group are one class, by two names: Manim CE's code writes both. A group
is a list of its parts: group[0] is the first one, group[1:3] is a group of
the second and the third, len(group) counts them, and for part in group: goes through
them. Every mobject's parts work the same way: a formula's terms, a graph's axes.
Group ¶
Code
import manimgx as m
class GroupExample(m.Scene):
def construct(self) -> None:
shapes = m.Group(
m.Circle(color=m.BLUE), m.Square(color=m.GREEN), m.Triangle()
).arrange(buff=1)
self.play(m.Create(shapes))
self.play(shapes.animate.scale(1.5).set_fill(opacity=0.5))
self.play(shapes[1].animate.shift(m.UP))
Mobjects together, of any kinds: paths, text, images, point clouds, other groups.
A group has no points of its own: its members are its submobjects, and whatever is
done to the group — moving, scaling, styling, animating — is done to them all.
VGroup is another name for it. A group can be indexed (group[0]), sliced (group[1:3] is a new group of those
members) and iterated over, and group + mobject, group - mobject, += and -=
add and remove members.
Its member type is inferred from what it is made with; a group meant to hold several
kinds says so once, as Group[Mobject](…), and Group[Integer](…) holds integers
only, so group[0] is an Integer to a type checker.
*mobjectsThe members, in drawing order: mobjects, or iterables of mobjects (each of their mobjects a member).
colorThe color of both fill and stroke (default white); None for the class's default.
fill_colorThe fill's color;
colorif not given. Several colors make a gradient alongsheen_direction.fill_opacityThe fill's opacity, from 0 to 1 (default 0: no fill).
stroke_colorThe stroke's color;
colorif not given. Several colors make a gradient.stroke_opacityThe stroke's opacity, from 0 to 1 (default 1).
stroke_widthThe stroke's width, in hundredths of a scene unit (default 4; 0: no stroke).
background_stroke_colorThe color of an outline drawn behind the fill (default black).
background_stroke_opacityThe outline's opacity, from 0 to 1 (default 1).
background_stroke_widthThe outline's width, in hundredths of a scene unit (default 0: none).
sheen_factorHow much the colors lighten toward
sheen_direction, from -1 to 1 (default 0); a negative factor darkens.sheen_directionThe direction the colors lighten toward (default
UL).joint_typeHow the stroke is joined where its path turns: round, beveled or mitered, as a two-dimensional scene draws it (see LineJointType; default AUTO: mitered).
cap_styleHow the stroke ends, at each end it shows (an open path's, a dash's): round, butt or square, as a two-dimensional scene draws it (see CapStyleType; default AUTO: butt).
shade_in_3dWhether a three-dimensional scene's light shades the mobject.
materialHow its surface reflects the scene's lights in a three-dimensional scene (see Material); None: Manim's shading (default).
nameA name for the mobject; its class's name if not given.
z_indexIts place in the drawing order: a higher index is drawn over a lower one (default 0).
targetThe state
MoveToTargetmoves the mobject to.
It also takes the style keywords.
Source
src/manimgx/mobject.py
submobjects ¶
The group's members, in drawing order.
add ¶
Add members after the ones the group has: mobjects, or iterables of mobjects (each of their mobjects a member).
A member already in the group moves to the end. Adding anything but mobjects, or the group to itself, raises an exception.
*mobjectsThe members to add, in order.
Source
src/manimgx/mobject.py
Add and remove parts¶
add_to_back ¶
Add submobjects before the ones the mobject has: they are drawn under them (at an equal z-index).
A mobject that is a submobject already moves to the front; what add refuses,
this refuses too.
*mobjectsThe mobjects to add, in order.
Source
src/manimgx/mobject.py
insert ¶
Insert a submobject at a place among the mobject's other submobjects.
A mobject that is a submobject already moves there; what add refuses, this
refuses too.
indexIts place in the list of the other submobjects, as
list.inserttakes it.mobjectThe mobject to insert.
Source
src/manimgx/mobject.py
remove ¶
Remove submobjects: those given that are among the mobject's own submobjects (not its submobjects' submobjects); the rest are ignored.
*mobjectsThe mobjects to remove.
Source
src/manimgx/mobject.py
get_family ¶
The mobject and all its descendants: itself, then each submobject's family in turn, each member once (where it last occurs, if the tree holds it twice).
Returns A new list.
Source
src/manimgx/mobject.py
family_members_with_points ¶
The members of the mobject's family that have points of their own: the ones that are drawn.
Returns A new list, in family order.
Source
src/manimgx/mobject.py
Lay parts out¶
arrange ¶

Code
import manimgx as m
class MobjectArrangeExample(m.Scene):
def construct(self) -> None:
sizes = (0.5, 1, 2)
squares = m.VGroup(*(m.Square(s, color=m.BLUE) for s in sizes))
squares.arrange(buff=0.5, aligned_edge=m.DOWN)
words = m.VGroup(m.Text("one"), m.Text("three"), m.Text("eleven"))
words.arrange(m.DOWN, aligned_edge=m.LEFT)
self.add(m.VGroup(squares, words).arrange(buff=1.5))
Lay the submobjects out in a row: each one beside the one before it (see
next_to), buff apart; then center the whole at the
origin.
mobject.arrange(direction=RIGHT, buff=DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, center=True, **kwargs)
directionThe way the row goes: RIGHT (default), DOWN for a column, …
buffThe gap between neighbours, in scene units (default 0.25).
centerWhether to center the mobject at the origin afterwards; if not, the first submobject stays where it was.
aligned_edgeThe edge, as a direction, along which the two line up besides the side they meet at: with the direction RIGHT and UP here, their tops line up (default ORIGIN: centered).
submobject_to_alignA part of the mobject to put beside the other in its place; the rest moves with it (default None: the whole mobject).
index_of_submobject_to_alignThe index of the part of each mobject to line up: this one's part goes beside the other's (default None: the whole of each).
coor_maskWhich coordinates may change: 1 for each axis the mobject moves along, 0 for one it keeps (default (1, 1, 1)).
Source
src/manimgx/mobject.py
arrange_in_grid ¶

Code
import manimgx as m
def cells() -> m.VGroup:
return m.VGroup(
*(
m.Square(0.9, color=m.BLUE).add(m.Text(str(i), font_size=36))
for i in range(1, 11)
)
)
class MobjectArrangeInGridExample(m.Scene):
def construct(self) -> None:
by_rows = cells().arrange_in_grid(rows=3, buff=0.2)
by_cols = cells().arrange_in_grid(rows=3, buff=0.2, flow_order="dr")
self.add(m.VGroup(by_rows, by_cols).arrange(buff=1.5))
Lay the submobjects out in a grid of rows and columns, centered where the mobject was.
Each row is as tall as its tallest mobject and each column as wide as its
widest, unless given. Each mobject sits in its cell as cell_alignment says,
but vertically as row_alignments says for its row and horizontally as
col_alignments says for its column, where they are given. Too few rows and
columns for the submobjects raise an exception.
mobject.arrange_in_grid(rows=None, cols=None, buff=MED_SMALL_BUFF, cell_alignment=ORIGIN, row_alignments=None, col_alignments=None, row_heights=None, col_widths=None, flow_order='rd')
rowsHow many rows; None for as many as
row_alignmentsorrow_heightslists, else as many as the submobjects need. With neitherrowsnorcols, the grid is as square as it can be.colsHow many columns; None for as many as
col_alignmentsorcol_widthslists, else as many as the submobjects need.buffThe gap between cells, in scene units: one for both directions, or (horizontal, vertical) (default 0.25).
cell_alignmentWhere each mobject sits in its cell, named by a direction: UL for its top left corner (default ORIGIN: centered).
row_alignmentsEach row's vertical alignment, top to bottom: a letter per row, "u" (up), "c" (center) or "d" (down); None: as the vertical part of
cell_alignmentsays (UL: up).col_alignmentsEach column's horizontal alignment, left to right: a letter per column, "l" (left), "c" (center) or "r" (right); None: as the horizontal part of
cell_alignmentsays (UL: left).row_heightsEach row's height, top to bottom, in scene units; None (for the grid or a row) for the height of the row's tallest mobject.
col_widthsEach column's width, left to right, in scene units; None (for the grid or a column) for the width of the column's widest mobject.
flow_orderThe order the cells are filled in: two letters, the direction a line of cells fills and then the direction the lines follow each other, "r" (right), "l" (left), "u" (up) or "d" (down). The default "rd" fills rows left to right, from the top down; "dr" fills columns top to bottom, from the left.
Source
src/manimgx/mobject.py
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 | |
Order parts¶
sort ¶
Sort the submobjects by a number: one computed from each one's center (by default its x coordinate, so left to right), or from each one itself.
Their order is the order they are drawn in (at an equal z-index), and the order
a lag_ratio staggers their animation in.
point_to_num_funcA function of a submobject's center, giving the number to sort it by.
submob_funcA function of a submobject, giving the number to sort it by, in place of
point_to_num_func.
Source
src/manimgx/mobject.py
shuffle ¶
Put the submobjects in a random order, drawn from Python's random.
recursiveWhether each submobject's submobjects are shuffled too, and theirs.
Source
src/manimgx/mobject.py
invert ¶
Reverse the order of the submobjects.
recursiveWhether each submobject's submobjects are reversed too, and theirs.
Source
src/manimgx/mobject.py
Name parts¶
VDict ¶
Code
import manimgx as m
class VDictExample(m.Scene):
def construct(self) -> None:
shapes = m.VDict(
{
"circle": m.Circle(radius=0.9, color=m.RED),
"square": m.Square(side_length=1.8, color=m.GREEN),
},
show_keys=True,
)
shapes["triangle"] = m.Triangle(color=m.BLUE)
self.add(shapes.arrange(buff=1))
self.play(shapes["square"].animate.set_color(m.YELLOW))
A group whose members have keys, as a dictionary has: vdict[key] is a member.
Members of any kind are added, replaced (vdict[key] = mobject) and removed by key;
like any group, it draws, moves and styles them together, in the order they were
added. With show_keys, each member is labeled with its key.
mapping_or_iterableThe first members: a dictionary of keys and mobjects, or (key, mobject) pairs.
show_keysWhether each member, added now or later, is labeled with its key: a Tex of
str(key)at its left, added to the member itself, so the label moves, animates and leaves with it, and counts in its size.colorThe color of both fill and stroke (default white); None for the class's default.
fill_colorThe fill's color;
colorif not given. Several colors make a gradient alongsheen_direction.fill_opacityThe fill's opacity, from 0 to 1 (default 0: no fill).
stroke_colorThe stroke's color;
colorif not given. Several colors make a gradient.stroke_opacityThe stroke's opacity, from 0 to 1 (default 1).
stroke_widthThe stroke's width, in hundredths of a scene unit (default 4; 0: no stroke).
background_stroke_colorThe color of an outline drawn behind the fill (default black).
background_stroke_opacityThe outline's opacity, from 0 to 1 (default 1).
background_stroke_widthThe outline's width, in hundredths of a scene unit (default 0: none).
sheen_factorHow much the colors lighten toward
sheen_direction, from -1 to 1 (default 0); a negative factor darkens.sheen_directionThe direction the colors lighten toward (default
UL).joint_typeHow the stroke is joined where its path turns: round, beveled or mitered, as a two-dimensional scene draws it (see LineJointType; default AUTO: mitered).
cap_styleHow the stroke ends, at each end it shows (an open path's, a dash's): round, butt or square, as a two-dimensional scene draws it (see CapStyleType; default AUTO: butt).
shade_in_3dWhether a three-dimensional scene's light shades the mobject.
materialHow its surface reflects the scene's lights in a three-dimensional scene (see Material); None: Manim's shading (default).
nameA name for the mobject; its class's name if not given.
z_indexIts place in the drawing order: a higher index is drawn over a lower one (default 0).
targetThe state
MoveToTargetmoves the mobject to.
It also takes the style keywords.
Source
src/manimgx/mobject.py
submob_dict ¶
The members, by key.
add ¶
Add members by key, after the group's.
Each is labeled with its key if the group shows its keys. A key the group has already
is given the new mobject, but the old one stays in the group: to replace a
member, set it (vdict[key] = mobject).
mapping_or_iterableA dictionary of keys and mobjects, or (key, mobject) pairs.
Source
src/manimgx/mobject.py
remove ¶
Remove the member with a key from the group.
Raises an exception if the group has no such key.
keyThe member's key.
Source
src/manimgx/mobject.py
index_labels ¶

Number the submobjects of a mobject: an Integer at the center of each, on a dark outline, to find a part's index.
A debugging help: add the labels to the scene to see them; they don't follow the mobject.
mobjectThe mobject whose submobjects are numbered, from 0.
label_heightEach label's height, in scene units.
It also takes
the DecimalNumber keywords.
Returns A new group of the labels, in order.
Source
src/manimgx/mobjects/numbers.py