表格¶
限定名称: 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]¶
基础类:
VGroup一个在屏幕上显示表格的mobject。
- Parameters:
表格 (可迭代[可迭代[浮点数 | 字符串 | VMobject]]) – 一个二维数组或列表的列表。表格的内容必须是
element_to_mobject中设置的可调用对象的有效输入。top_left_entry (VMobject | None) – 表格的左上角条目,只有在提供了行和列标签时才能指定。
v_buff (float) – 传递给
arrange_in_grid()的垂直缓冲区,默认值为0.8。h_buff (float) – 传递给
arrange_in_grid()的水平缓冲区,默认值为1.3。include_outer_lines (bool) –
True如果表格应包含外边框,默认为 False。add_background_rectangles_to_entries (bool) –
True如果应该为条目添加背景矩形,默认为False。entries_background_color (ParsableManimColor) – 如果
add_background_rectangles_to_entries为True,则条目的背景颜色。include_background_rectangle (bool) –
True如果表格应该有背景矩形,默认为False。background_rectangle_color (ParsableManimColor) – 如果
include_background_rectangle是True,则为表格的背景颜色。element_to_mobject (Callable[[float | str | VMobject], VMobject]) – 应用于表格条目的
Mobject类。默认情况下为段落。常见选择请参见text_mobject/tex_mobject。element_to_mobject_config (dict) – 传递给
element_to_mobject的自定义配置,默认为 {}。arrange_in_grid_config (dict) – 传递给
arrange_in_grid()的字典,用于自定义表格的排列方式。line_config (dict) – 传递给
Line的字典,用于自定义表格的线条。kwargs – 传递给
VGroup的额外参数。
示例
示例: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)示例: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)方法
为表格的每个条目添加一个黑色的
BackgroundRectangle。通过在表格的特定位置添加
BackgroundRectangle来高亮显示一个单元格。为表格定制的创建类型函数。
返回一个特定的单元格作为一个矩形的
Polygon,不包括入口。返回表的列标签。
返回表的各个条目(包括标签),如果设置了参数
pos,则返回特定条目。返回表的各个条目(不带标签),如果设置了参数
pos,则返回特定条目。返回给定位置单元格的
BackgroundRectangle。返回表格的水平线。
返回表的标签。
返回表的行标签。
返回表格的垂直线。
按比例缩放大小。
为表格的每一列设置单独的颜色。
为表格的每一行设置单独的颜色。
属性
animate用于动画化
self的任何方法的应用。animation_overridescolordepthmobject的深度。
fill_color如果有多种颜色(用于渐变),则返回第一个颜色
heightmobject的高度。
n_points_per_curvesheen_factorstroke_colorwidthmobject的宽度。
- _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)¶
初始化自身。有关准确的签名,请参阅 help(type(self))。
- Parameters:
表格 (可迭代[可迭代[浮点数 | 字符串 | VMobject]])
row_labels (可迭代对象[VMobject] | 无)
col_labels (可迭代对象[VMobject] | 无)
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 (字典)
arrange_in_grid_config (字典)
line_config (字典)
- add_background_to_entries(color=ManimColor('#000000'))[来源]¶
为表格的每个条目添加一个黑色的
BackgroundRectangle。- Parameters:
颜色 (ParsableManimColor)
- Return type:
- add_highlighted_cell(pos=(1, 1), color=ManimColor('#FFFF00'), **kwargs)[来源]¶
通过在表格的特定位置添加
BackgroundRectangle来高亮显示一个单元格。- Parameters:
pos (Sequence[int]) – 表格中特定条目的位置。
(1,1)表示表格的左上角条目。color (ParsableManimColor) – 用于突出显示单元格的颜色。
kwargs – 传递给
BackgroundRectangle的额外参数。
- Return type:
示例
示例: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]¶
为表格定制的创建类型函数。
- Parameters:
lag_ratio (float) – 动画的滞后比率。
line_animation (Callable[[VMobject | VGroup], 动画]) – 表格线条的动画样式,参见
creation中的示例。label_animation (Callable[[VMobject | VGroup], 动画]) – 表格标签的动画样式,参见
creation中的示例。element_animation (Callable[[VMobject | VGroup], 动画]) – 表格元素的动画样式,参见
creation中的示例。entry_animation (Callable[[VMobject | VGroup], 动画]) – 表格背景的进入动画,参见
creation中的示例。kwargs – 传递给创建动画的进一步参数。
- Returns:
包含线条和元素创建的AnimationGroup。
- Return type:
示例
示例: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]¶
返回一个特定的单元格作为一个矩形的
Polygon,不包括入口。- Parameters:
pos (Sequence[int]) – 表格中特定条目的位置。
(1,1)表示表格的左上角条目。kwargs – 传递给
Polygon的额外参数。
- Returns:
多边形模仿表格中的一个特定单元格。
- Return type:
示例
示例: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()[来源]¶
返回表的列标签。
- Returns:
包含表格列标签的VGroup。
- Return type:
示例
示例: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]¶
-
示例
示例: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]¶
返回表的各个条目(包括标签),如果设置了参数
pos,则返回特定条目。- Parameters:
pos (Sequence[int] | None) – 表格中特定条目的位置。
(1,1)表示表格的左上角条目。- Returns:
- Return type:
示例
示例: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)[来源]¶
返回表的各个条目(不带标签)或如果设置了参数
pos,则返回特定条目。- Parameters:
pos (Sequence[int] | None) – 表格中特定条目的位置。
(1,1)表示表格的左上角条目(不包括标签)。- Returns:
- Return type:
示例
示例: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)[来源]¶
返回给定位置单元格的
BackgroundRectangle。- Parameters:
pos (Sequence[int]) – 表格中特定条目的位置。
(1,1)表示表格的左上角条目。color (ParsableManimColor) – 用于突出显示单元格的颜色。
kwargs – 传递给
BackgroundRectangle的额外参数。
- Return type:
示例
示例:获取高亮单元格示例 ¶
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()[来源]¶
返回表格的水平线。
示例
示例: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()[来源]¶
返回表的标签。
示例
示例: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()[来源]¶
返回表的行标签。
示例
示例: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()[来源]¶
-
示例
示例: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()[来源]¶
返回表格的垂直线。
示例
示例: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)[来源]¶
按比例缩放大小。
默认行为是围绕mobject的中心进行缩放。
- Parameters:
scale_factor (float) – 缩放因子 \(\alpha\)。如果 \(0 < |\alpha| < 1\),对象 会缩小,而对于 \(|\alpha| > 1\) 则会放大。此外, 如果 \(\alpha < 0\),对象也会被翻转。
kwargs – 传递给
apply_points_function_about_point()的额外关键字参数。
- Returns:
self- Return type:
Mobject
示例
示例:MobjectScaleExample ¶
from manim import * class MobjectScaleExample(Scene): def construct(self): f1 = Text("F") f2 = Text("F").scale(2) f3 = Text("F").scale(0.5) f4 = Text("F").scale(-1) vgroup = VGroup(f1, f2, f3, f4).arrange(6 * RIGHT) self.add(vgroup)
class MobjectScaleExample(Scene): def construct(self): f1 = Text("F") f2 = Text("F").scale(2) f3 = Text("F").scale(0.5) f4 = Text("F").scale(-1) vgroup = VGroup(f1, f2, f3, f4).arrange(6 * RIGHT) self.add(vgroup)另请参阅
move_to()
- set_column_colors(*colors)[来源]¶
为表格的每一列设置单独的颜色。
- Parameters:
colors (Iterable[ParsableManimColor]) – 一个可迭代的颜色集合;每种颜色对应一列。
- Return type:
示例
示例: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)[来源]¶
为表格的每一行设置单独的颜色。
- Parameters:
colors (Iterable[ParsableManimColor]) – 一个可迭代的颜色集合;每种颜色对应一行。
- Return type:
示例
示例: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)