Reference: Text, Tables and Matrices

Words, maths, numbers, code, tables, matrices.

Text

See Text and maths for a guide.

  • Text(text, font_size=DEFAULT_FONT_SIZE, font="", weight=NORMAL, slant=NORMAL, line_spacing=-1, t2c=None, letter_spacing=0): Words, drawn as outlines. font="serif" or "mono" for the other built-in fonts, or a font file next to the .py ("Brand.ttf"); weight=BOLD, slant=ITALIC; t2c={"word": BLUE} colours a word.
  • MarkupText(text, fill_opacity=1, stroke_width=0, color=None, font_size=DEFAULT_FONT_SIZE, line_spacing=-1, font="", slant=NORMAL, weight=NORMAL, justify=False): Text with simple markup: <b>, <i> and coloured spans.
  • Paragraph(*text, line_spacing=-1, alignment=None): Several lines of text, one per argument.
  • BulletedList(*items, buff=MED_LARGE_BUFF, dot_scale_factor=2, tex_environment=None, dot_buff=SMALL_BUFF): A list with a bullet before each item (maths-style text).
    • .fade_all_but(index, opacity=0.5): Fades every item except one, to focus on it.
  • Title(*text_parts, include_underline=True, match_underline_width_to_text=False, underline_buff=MED_SMALL_BUFF): A Tex at the top of the picture, underlined.

Maths

  • MathTex(*tex_strings, arg_separator=None, substrings_to_isolate=None, tex_to_color_map=None, font_size=DEFAULT_FONT_SIZE, tex_environment=None): Maths written as LaTeX (laid out by KaTeX). Each string is a part: eq[0]; {{ }} splits parts too.
    • .get_parts_by_tex(tex, substring=True, case_sensitive=True): Every part containing (or equal to) some TeX, as a group.
    • .get_part_by_tex(tex): The first part containing some TeX.
    • .index_of_part_by_tex(tex) (also .index_of_part): The number of the first part containing some TeX.
    • .set_color_by_tex(tex, color): Colours every part containing some TeX.
    • .set_color_by_tex_to_color_map(texs_to_color_map): Colours parts from a {tex: colour} dictionary.
  • Tex(*tex_strings, arg_separator=None, substrings_to_isolate=None, tex_to_color_map=None, font_size=DEFAULT_FONT_SIZE, tex_environment=None): Text with maths between $ signs: Tex(r"Area $= \pi r^2$").
from pymations import *

eq = MathTex("a^2", "+", "b^2", "=", "c^2", font_size=72)
eq.set_color_by_tex("c", YELLOW)
play(Write(eq))

Numbers

  • DecimalNumber(number=0, num_decimal_places=2, mob_class=None, include_sign=False, group_with_commas=True, digit_buff_per_font_unit=0.001, show_ellipsis=False, unit=None, unit_buff_per_font_unit=0, include_background_rectangle=False, edge_to_fix=LEFT, font_size=DEFAULT_FONT_SIZE, stroke_width=0, fill_opacity=1.0): A number with a fixed number of decimal places; change it cheaply with set_value.
    • .set_value(number): Shows a new number.
    • .get_value(): The number shown.
    • .increment_value(delta_t=1): Adds to the number shown.
  • Integer(number=0, num_decimal_places=0): A whole number.
  • Variable(var, label, var_type=None, num_decimal_places=2): label = value with a tracker, var.tracker, that the value follows.
from pymations import *

n = DecimalNumber(0, num_decimal_places=1, font_size=96)
add(n)
play(ChangeDecimalToValue(n, 10), run_time=2)

Code

  • Code(code_file=None, code_string=None, language=None, formatter_style="vim", tab_width=4, add_line_numbers=True, line_numbers_from=1, background="rectangle", background_config=None, paragraph_config=None): Program code in a monospace font with syntax colours and line numbers.
    • .code: The code lines, as a group.
    • .line_numbers: The line numbers, as a group.
    • .background: The panel behind the code.

Tables

  • Table(table, row_labels=None, col_labels=None, top_left_entry=None, v_buff=0.8, h_buff=1.3, include_outer_lines=False, include_inner_lines=True, add_background_rectangles_to_entries=False, entries_background_color=BLACK, include_background_rectangle=False, background_rectangle_color=BLACK, element_to_mobject=None, element_to_mobject_config=None, arrange_in_grid_config=None, line_config=None): A table of text: a list of rows; row_labels and col_labels add headings.
    • .get_entries(pos=None): Every cell's contents, or one by (row, column) (from 1).
    • .get_entries_without_labels(pos=None): The cells without the headings.
    • .get_rows(): The rows, as groups.
    • .get_columns(): The columns, as groups.
    • .get_horizontal_lines(): The lines between rows.
    • .get_vertical_lines(): The lines between columns.
    • .get_cell(pos): A rectangle round one cell (row, column), to highlight it.
  • MathTable(table, row_labels=None, col_labels=None, top_left_entry=None, v_buff=0.8, h_buff=1.3, include_outer_lines=False, include_inner_lines=True, add_background_rectangles_to_entries=False, entries_background_color=BLACK, include_background_rectangle=False, background_rectangle_color=BLACK, element_to_mobject=None, element_to_mobject_config=None, arrange_in_grid_config=None, line_config=None): A Table whose cells are maths.
  • IntegerTable(table, element_to_mobject=Integer): A Table of whole numbers.
  • DecimalTable(table, element_to_mobject=DecimalNumber, element_to_mobject_config=None): A Table of decimal numbers.
from pymations import *

t = Table([["1", "2"], ["3", "4"]], col_labels=[Text("a"), Text("b")])
play(Create(t))

Matrices

  • Matrix(matrix, v_buff=0.8, h_buff=1.3, bracket_h_buff=MED_SMALL_BUFF, bracket_v_buff=MED_SMALL_BUFF, add_background_rectangles_to_entries=False, include_background_rectangle=False, element_to_mobject=None, element_to_mobject_config=None, element_alignment_corner=DR, left_bracket="[", right_bracket="]", stretch_brackets=True, bracket_config=None): A matrix in square brackets: a list of rows.
    • .get_entries(): Every entry, as a group.
    • .get_mob_matrix(): The entries as a list of rows.
    • .get_rows(): The rows, as groups.
    • .get_columns(): The columns, as groups.
    • .get_brackets(): The two brackets.
    • .set_column_colors(*colors): Colours each column, left to right.
    • .set_row_colors(*colors): Colours each row, top to bottom.
  • IntegerMatrix(matrix, v_buff=0.8, h_buff=1.3, bracket_h_buff=MED_SMALL_BUFF, bracket_v_buff=MED_SMALL_BUFF, add_background_rectangles_to_entries=False, include_background_rectangle=False, element_to_mobject=None, element_to_mobject_config=None, element_alignment_corner=DR, left_bracket="[", right_bracket="]", stretch_brackets=True, bracket_config=None): A Matrix of whole numbers.
  • DecimalMatrix(matrix, v_buff=0.8, h_buff=1.3, bracket_h_buff=MED_SMALL_BUFF, bracket_v_buff=MED_SMALL_BUFF, add_background_rectangles_to_entries=False, include_background_rectangle=False, element_to_mobject=None, element_to_mobject_config=None, element_alignment_corner=DR, left_bracket="[", right_bracket="]", stretch_brackets=True, bracket_config=None): A Matrix of decimal numbers.
  • MobjectMatrix(matrix, v_buff=0.8, h_buff=1.3, bracket_h_buff=MED_SMALL_BUFF, bracket_v_buff=MED_SMALL_BUFF, add_background_rectangles_to_entries=False, include_background_rectangle=False, element_to_mobject=None, element_to_mobject_config=None, element_alignment_corner=DR, left_bracket="[", right_bracket="]", stretch_brackets=True, bracket_config=None): A Matrix whose entries are any objects.
from pymations import *

m = Matrix([[1, 2], [3, 4]])
play(Write(m))
play(m.animate.set_column_colors(BLUE, GREEN))