Skip to content

Commit ec9b426

Browse files
committed
Merge branch 'pr/49'
2 parents 1591d15 + 7e15134 commit ec9b426

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

manim/mobject/matrix.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Matrix(VMobject):
6363
"element_to_mobject": TexMobject,
6464
"element_to_mobject_config": {},
6565
"element_alignment_corner": DR,
66+
"left_bracket": "\\big[",
67+
"right_bracket": "\\big]",
6668
}
6769

6870
def __init__(self, matrix, **kwargs):
@@ -76,7 +78,7 @@ def __init__(self, matrix, **kwargs):
7678
self.organize_mob_matrix(mob_matrix)
7779
self.elements = VGroup(*mob_matrix.flatten())
7880
self.add(self.elements)
79-
self.add_brackets()
81+
self.add_brackets(self.left_bracket,self.right_bracket)
8082
self.center()
8183
self.mob_matrix = mob_matrix
8284
if self.add_background_rectangles_to_entries:
@@ -100,8 +102,8 @@ def organize_mob_matrix(self, matrix):
100102
)
101103
return self
102104

103-
def add_brackets(self):
104-
bracket_pair = TexMobject("\\big[", "\\big]")
105+
def add_brackets(self, left = "\\big[", right = "\\big]"):
106+
bracket_pair = TexMobject(left, right)
105107
bracket_pair.scale(2)
106108
bracket_pair.stretch_to_fit_height(
107109
self.get_height() + 2 * self.bracket_v_buff
@@ -125,6 +127,37 @@ def set_column_colors(self, *colors):
125127
column.set_color(color)
126128
return self
127129

130+
def get_rows(self):
131+
"""Return rows of the matrix as VGroups
132+
133+
Returns
134+
--------
135+
List[:class:`~.VGroup`]
136+
Each VGroup contains a row of the matrix.
137+
"""
138+
return VGroup(*[
139+
VGroup(*self.mob_matrix[i, :])
140+
for i in range(self.mob_matrix.shape[1])
141+
])
142+
143+
def set_row_colors(self, *colors):
144+
"""Set individual colors for each row of the matrix
145+
146+
Parameters
147+
----------
148+
colors : :class:`str`
149+
The list of colors; each color specified corresponds to a row.
150+
151+
Returns
152+
-------
153+
:class:`Matrix`
154+
The current matrix object (self).
155+
"""
156+
rows = self.get_rows()
157+
for color, row in zip(colors, rows):
158+
row.set_color(color)
159+
return self
160+
128161
def add_background_to_entries(self):
129162
for mob in self.get_entries():
130163
mob.add_background_rectangle()

0 commit comments

Comments
 (0)