Table¶
Qualified name: manim.mobject.table.Table
- class Table(table, row_labels=None, col_labels=None, top_left_entry=None, v_buff=0.8, h_buff=1.3, include_outer_lines=False, add_background_rectangles_to_entries=False, entries_background_color=ManimColor('#000000'), include_background_rectangle=False, background_rectangle_color=ManimColor('#000000'), element_to_mobject=<class 'manim.mobject.text.text_mobject.Paragraph'>, element_to_mobject_config={}, arrange_in_grid_config={}, line_config={}, **kwargs)[source]¶
Bases:
VGroupA mobject that displays a table on the screen.
- Parameters:
table (Iterable[Iterable[float | str | VMobject]]) – A 2D array or list of lists. Content of the table has to be a valid input for the callable set in
element_to_mobject.row_labels (Iterable[VMobject] | None) – List of
VMobjectrepresenting the labels of each row.col_labels (Iterable[VMobject] | None) – List of
VMobjectrepresenting the labels of each column.top_left_entry (VMobject | None) – The top-left entry of the table, can only be specified if row and column labels are given.
v_buff (float) – Vertical buffer passed to
arrange_in_grid(), by default 0.8.h_buff (float) – Horizontal buffer passed to
arrange_in_grid(), by default 1.3.include_outer_lines (bool) –
Trueif the table should include outer lines, by default False.add_background_rectangles_to_entries (bool) –
Trueif background rectangles should be added to entries, by defaultFalse.entries_background_color (ParsableManimColor) – Background color of entries if
add_background_rectangles_to_entriesisTrue.include_background_rectangle (bool) –
Trueif the table should have a background rectangle, by defaultFalse.background_rectangle_color (ParsableManimColor) – Background color of table if
include_background_rectangleisTrue.element_to_mobject (Callable[[float | str | VMobject], VMobject]) – The
Mobjectclass applied to the table entries. by defaultParagraph. For common choices, seetext_mobject/tex_mobject.element_to_mobject_config (dict) – Custom configuration passed to
element_to_mobject, by default {}.arrange_in_grid_config (dict) – Dict passed to
arrange_in_grid(), customizes the arrangement of the table.line_config (dict) – Dict passed to
Line, customizes the lines of the table.kwargs – Additional arguments to be passed to
VGroup.
Examples
Example: TableExamples ¶
from manim import * class TableExamples(Scene): def construct(self): t0 = Table( [["This", "is a"], ["simple", "Table in \\n Manim."]]) t1 = Table( [["This", "is a"], ["simple", "Table."]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) t1.add_highlighted_cell((2,2), color=YELLOW) t2 = Table( [["This", "is a"], ["simple", "Table."]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")], top_left_entry=Star().scale(0.3), include_outer_lines=True, arrange_in_grid_config={"cell_alignment": RIGHT}) t2.add(t2.get_cell((2,2), color=RED)) t3 = Table( [["This", "is a"], ["simple", "Table."]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")], top_left_entry=Star().scale(0.3), include_outer_lines=True, line_config={"stroke_width": 1, "color": YELLOW}) t3.remove(*t3.get_vertical_lines()) g = Group( t0,t1,t2,t3 ).scale(0.7).arrange_in_grid(buff=1) self.add(g)
class TableExamples(Scene): def construct(self): t0 = Table( [["This", "is a"], ["simple", "Table in \\n Manim."]]) t1 = Table( [["This", "is a"], ["simple", "Table."]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) t1.add_highlighted_cell((2,2), color=YELLOW) t2 = Table( [["This", "is a"], ["simple", "Table."]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")], top_left_entry=Star().scale(0.3), include_outer_lines=True, arrange_in_grid_config={"cell_alignment": RIGHT}) t2.add(t2.get_cell((2,2), color=RED)) t3 = Table( [["This", "is a"], ["simple", "Table."]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")], top_left_entry=Star().scale(0.3), include_outer_lines=True, line_config={"stroke_width": 1, "color": YELLOW}) t3.remove(*t3.get_vertical_lines()) g = Group( t0,t1,t2,t3 ).scale(0.7).arrange_in_grid(buff=1) self.add(g)Example: BackgroundRectanglesExample ¶
from manim import * class BackgroundRectanglesExample(Scene): def construct(self): background = Rectangle(height=6.5, width=13) background.set_fill(opacity=.5) background.set_color([TEAL, RED, YELLOW]) self.add(background) t0 = Table( [["This", "is a"], ["simple", "Table."]], add_background_rectangles_to_entries=True) t1 = Table( [["This", "is a"], ["simple", "Table."]], include_background_rectangle=True) g = Group(t0, t1).scale(0.7).arrange(buff=0.5) self.add(g)
class BackgroundRectanglesExample(Scene): def construct(self): background = Rectangle(height=6.5, width=13) background.set_fill(opacity=.5) background.set_color([TEAL, RED, YELLOW]) self.add(background) t0 = Table( [["This", "is a"], ["simple", "Table."]], add_background_rectangles_to_entries=True) t1 = Table( [["This", "is a"], ["simple", "Table."]], include_background_rectangle=True) g = Group(t0, t1).scale(0.7).arrange(buff=0.5) self.add(g)Methods
Adds a black
BackgroundRectangleto each entry of the table.Highlights one cell at a specific position on the table by adding a
BackgroundRectangle.Customized create-type function for tables.
Returns one specific cell as a rectangular
Polygonwithout the entry.Return the column labels of the table.
Return the individual entries of the table (including labels) or one specific entry if the parameter,
pos, is set.Return the individual entries of the table (without labels) or one specific entry if the parameter,
pos, is set.Returns a
BackgroundRectangleof the cell at the given position.Return the horizontal lines of the table.
Returns the labels of the table.
Return the row labels of the table.
Return the vertical lines of the table.
Scale the size by a factor.
Set individual colors for each column of the table.
Set individual colors for each row of the table.
Attributes
alwaysCall a method on a mobject every frame.
animateUsed to animate the application of any method of
self.animation_overridescolordepthThe depth of the mobject.
fill_colorIf there are multiple colors (for gradient) this returns the first one
heightThe height of the mobject.
n_points_per_curvesheen_factorstroke_colorwidthThe width of the mobject.
- _original__init__(table, row_labels=None, col_labels=None, top_left_entry=None, v_buff=0.8, h_buff=1.3, include_outer_lines=False, add_background_rectangles_to_entries=False, entries_background_color=ManimColor('#000000'), include_background_rectangle=False, background_rectangle_color=ManimColor('#000000'), element_to_mobject=<class 'manim.mobject.text.text_mobject.Paragraph'>, element_to_mobject_config={}, arrange_in_grid_config={}, line_config={}, **kwargs)¶
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
table (Iterable[Iterable[float | str | VMobject]])
row_labels (Iterable[VMobject] | None)
col_labels (Iterable[VMobject] | None)
top_left_entry (VMobject | None)
v_buff (float)
h_buff (float)
include_outer_lines (bool)
add_background_rectangles_to_entries (bool)
entries_background_color (ParsableManimColor)
include_background_rectangle (bool)
background_rectangle_color (ParsableManimColor)
element_to_mobject (Callable[[float | str | VMobject], VMobject])
element_to_mobject_config (dict)
arrange_in_grid_config (dict)
line_config (dict)
- add_background_to_entries(color=ManimColor('#000000'))[source]¶
Adds a black
BackgroundRectangleto each entry of the table.- Parameters:
color (ParsableManimColor)
- Return type:
- add_highlighted_cell(pos=(1, 1), color=ManimColor('#FFFF00'), **kwargs)[source]¶
Highlights one cell at a specific position on the table by adding a
BackgroundRectangle.- Parameters:
pos (Sequence[int]) – The position of a specific entry on the table.
(1,1)being the top left entry of the table.color (ParsableManimColor) – The color used to highlight the cell.
kwargs – Additional arguments to be passed to
BackgroundRectangle.
- Return type:
Examples
Example: AddHighlightedCellExample ¶
from manim import * class AddHighlightedCellExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.add_highlighted_cell((2,2), color=GREEN) self.add(table)
class AddHighlightedCellExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.add_highlighted_cell((2,2), color=GREEN) self.add(table)
- create(lag_ratio=1, line_animation=<class 'manim.animation.creation.Create'>, label_animation=<class 'manim.animation.creation.Write'>, element_animation=<class 'manim.animation.creation.Create'>, entry_animation=<class 'manim.animation.fading.FadeIn'>, **kwargs)[source]¶
Customized create-type function for tables.
- Parameters:
lag_ratio (float) – The lag ratio of the animation.
line_animation (Callable[[VMobject | VGroup], Animation]) – The animation style of the table lines, see
creationfor examples.label_animation (Callable[[VMobject | VGroup], Animation]) – The animation style of the table labels, see
creationfor examples.element_animation (Callable[[VMobject | VGroup], Animation]) – The animation style of the table elements, see
creationfor examples.entry_animation (Callable[[VMobject | VGroup], Animation]) – The entry animation of the table background, see
creationfor examples.kwargs – Further arguments passed to the creation animations.
- Returns:
AnimationGroup containing creation of the lines and of the elements.
- Return type:
Examples
Example: CreateTableExample ¶
from manim import * class CreateTableExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")], include_outer_lines=True) self.play(table.create()) self.wait()
class CreateTableExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")], include_outer_lines=True) self.play(table.create()) self.wait()
- get_cell(pos=(1, 1), **kwargs)[source]¶
Returns one specific cell as a rectangular
Polygonwithout the entry.- Parameters:
pos (Sequence[int]) – The position of a specific entry on the table.
(1,1)being the top left entry of the table.kwargs – Additional arguments to be passed to
Polygon.
- Returns:
Polygon mimicking one specific cell of the Table.
- Return type:
Examples
Example: GetCellExample ¶
from manim import * class GetCellExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) cell = table.get_cell((2,2), color=RED) self.add(table, cell)
class GetCellExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) cell = table.get_cell((2,2), color=RED) self.add(table, cell)
- get_col_labels()[source]¶
Return the column labels of the table.
- Returns:
VGroup containing the column labels of the table.
- Return type:
Examples
Example: GetColLabelsExample ¶
from manim import * class GetColLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) lab = table.get_col_labels() for item in lab: item.set_color(random_bright_color()) self.add(table)
class GetColLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) lab = table.get_col_labels() for item in lab: item.set_color(random_bright_color()) self.add(table)
- get_columns()[source]¶
Return columns of the table as a
VGroupofVGroup.Examples
Example: GetColumnsExample ¶
from manim import * class GetColumnsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.add(SurroundingRectangle(table.get_columns()[1])) self.add(table)
class GetColumnsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.add(SurroundingRectangle(table.get_columns()[1])) self.add(table)
- get_entries(pos=None)[source]¶
Return the individual entries of the table (including labels) or one specific entry if the parameter,
pos, is set.- Parameters:
pos (Sequence[int] | None) – The position of a specific entry on the table.
(1,1)being the top left entry of the table.- Returns:
VGroupcontaining all entries of the table (including labels) or theVMobjectat the given position ifposis set.- Return type:
Examples
Example: GetEntriesExample ¶
from manim import * class GetEntriesExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) ent = table.get_entries() for item in ent: item.set_color(random_bright_color()) table.get_entries((2,2)).rotate(PI) self.add(table)
class GetEntriesExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) ent = table.get_entries() for item in ent: item.set_color(random_bright_color()) table.get_entries((2,2)).rotate(PI) self.add(table)
- get_entries_without_labels(pos=None)[source]¶
Return the individual entries of the table (without labels) or one specific entry if the parameter,
pos, is set.- Parameters:
pos (Sequence[int] | None) – The position of a specific entry on the table.
(1,1)being the top left entry of the table (without labels).- Returns:
VGroupcontaining all entries of the table (without labels) or theVMobjectat the given position ifposis set.- Return type:
Examples
Example: GetEntriesWithoutLabelsExample ¶
from manim import * class GetEntriesWithoutLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) ent = table.get_entries_without_labels() colors = [BLUE, GREEN, YELLOW, RED] for k in range(len(colors)): ent[k].set_color(colors[k]) table.get_entries_without_labels((2,2)).rotate(PI) self.add(table)
class GetEntriesWithoutLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) ent = table.get_entries_without_labels() colors = [BLUE, GREEN, YELLOW, RED] for k in range(len(colors)): ent[k].set_color(colors[k]) table.get_entries_without_labels((2,2)).rotate(PI) self.add(table)
- get_highlighted_cell(pos=(1, 1), color=ManimColor('#FFFF00'), **kwargs)[source]¶
Returns a
BackgroundRectangleof the cell at the given position.- Parameters:
pos (Sequence[int]) – The position of a specific entry on the table.
(1,1)being the top left entry of the table.color (ParsableManimColor) – The color used to highlight the cell.
kwargs – Additional arguments to be passed to
BackgroundRectangle.
- Return type:
Examples
Example: GetHighlightedCellExample ¶
from manim import * class GetHighlightedCellExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) highlight = table.get_highlighted_cell((2,2), color=GREEN) table.add_to_back(highlight) self.add(table)
class GetHighlightedCellExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) highlight = table.get_highlighted_cell((2,2), color=GREEN) table.add_to_back(highlight) self.add(table)
- get_horizontal_lines()[source]¶
Return the horizontal lines of the table.
Examples
Example: GetHorizontalLinesExample ¶
from manim import * class GetHorizontalLinesExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.get_horizontal_lines().set_color(RED) self.add(table)
class GetHorizontalLinesExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.get_horizontal_lines().set_color(RED) self.add(table)
- get_labels()[source]¶
Returns the labels of the table.
Examples
Example: GetLabelsExample ¶
from manim import * class GetLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) lab = table.get_labels() colors = [BLUE, GREEN, YELLOW, RED] for k in range(len(colors)): lab[k].set_color(colors[k]) self.add(table)
class GetLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) lab = table.get_labels() colors = [BLUE, GREEN, YELLOW, RED] for k in range(len(colors)): lab[k].set_color(colors[k]) self.add(table)
- get_row_labels()[source]¶
Return the row labels of the table.
Examples
Example: GetRowLabelsExample ¶
from manim import * class GetRowLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) lab = table.get_row_labels() for item in lab: item.set_color(random_bright_color()) self.add(table)
class GetRowLabelsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) lab = table.get_row_labels() for item in lab: item.set_color(random_bright_color()) self.add(table)
- get_rows()[source]¶
Return the rows of the table as a
VGroupofVGroup.Examples
Example: GetRowsExample ¶
from manim import * class GetRowsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.add(SurroundingRectangle(table.get_rows()[1])) self.add(table)
class GetRowsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.add(SurroundingRectangle(table.get_rows()[1])) self.add(table)
- get_vertical_lines()[source]¶
Return the vertical lines of the table.
Examples
Example: GetVerticalLinesExample ¶
from manim import * class GetVerticalLinesExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.get_vertical_lines()[0].set_color(RED) self.add(table)
class GetVerticalLinesExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")]) table.get_vertical_lines()[0].set_color(RED) self.add(table)
- scale(scale_factor, **kwargs)[source]¶
Scale the size by a factor.
Default behavior is to scale about the center of the vmobject.
- Parameters:
scale_factor (float) – The scaling factor \(\alpha\). If \(0 < |\alpha| < 1\), the mobject will shrink, and for \(|\alpha| > 1\) it will grow. Furthermore, if \(\alpha < 0\), the mobject is also flipped.
scale_stroke – Boolean determining if the object’s outline is scaled when the object is scaled. If enabled, and object with 2px outline is scaled by a factor of .5, it will have an outline of 1px.
kwargs – Additional keyword arguments passed to
scale().
- Returns:
self- Return type:
VMobject
Examples
Example: MobjectScaleExample ¶
from manim import * class MobjectScaleExample(Scene): def construct(self): c1 = Circle(1, RED).set_x(-1) c2 = Circle(1, GREEN).set_x(1) vg = VGroup(c1, c2) vg.set_stroke(width=50) self.add(vg) self.play( c1.animate.scale(.25), c2.animate.scale(.25, scale_stroke=True) )
class MobjectScaleExample(Scene): def construct(self): c1 = Circle(1, RED).set_x(-1) c2 = Circle(1, GREEN).set_x(1) vg = VGroup(c1, c2) vg.set_stroke(width=50) self.add(vg) self.play( c1.animate.scale(.25), c2.animate.scale(.25, scale_stroke=True) )See also
move_to()
- set_column_colors(*colors)[source]¶
Set individual colors for each column of the table.
- Parameters:
colors (Iterable[TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor')]) – An iterable of colors; each color corresponds to a column.
- Return type:
Examples
Example: SetColumnColorsExample ¶
from manim import * class SetColumnColorsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")] ).set_column_colors([RED,BLUE], GREEN) self.add(table)
class SetColumnColorsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")] ).set_column_colors([RED,BLUE], GREEN) self.add(table)
- set_row_colors(*colors)[source]¶
Set individual colors for each row of the table.
- Parameters:
colors (Iterable[TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor')]) – An iterable of colors; each color corresponds to a row.
- Return type:
Examples
Example: SetRowColorsExample ¶
from manim import * class SetRowColorsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")] ).set_row_colors([RED,BLUE], GREEN) self.add(table)
class SetRowColorsExample(Scene): def construct(self): table = Table( [["First", "Second"], ["Third","Fourth"]], row_labels=[Text("R1"), Text("R2")], col_labels=[Text("C1"), Text("C2")] ).set_row_colors([RED,BLUE], GREEN) self.add(table)