manim.mobject.matrix.Matrix

class Matrix(matrix, v_buff=0.8, h_buff=1.3, bracket_h_buff=0.25, bracket_v_buff=0.25, add_background_rectangles_to_entries=False, include_background_rectangle=False, element_to_mobject=<class 'manim.mobject.svg.tex_mobject.MathTex'>, element_to_mobject_config={}, element_alignment_corner=array([ 1., -1., 0.]), left_bracket='\\big[', right_bracket='\\big]', **kwargs)[source]

Bases: manim.mobject.types.vectorized_mobject.VMobject

A mobject that displays a matrix on the screen.

Parameters
  • matrix (typing.Iterable) – A numpy 2d array or list of lists

  • v_buff (float, optional) – vertical buffer, by default 0.8

  • h_buff (float, optional) – horizontal buffer, by default 1.3

  • bracket_h_buff (float, optional) – bracket horizonal buffer, by default MED_SMALL_BUFF

  • bracket_v_buff (float, optional) – bracket veritical buffer, by default MED_SMALL_BUFF

  • add_background_rectangles_to_entries (bool, optional) – True if should add backgraound rectangles to entries, by default False

  • include_background_rectangle (bool, optional) – True if should include background rectangle, by default False

  • element_to_mobject (Mobject, optional) – element to mobject, by default MathTex

  • element_to_mobject_config (Dict[str, Mobject], optional) – element to mobject config, by default {}

  • element_alignment_corner (np.ndarray, optional) – the element alignment corner, by default DR

  • left_bracket (str, optional) – the left bracket type, by default “\big[”

  • right_bracket (str, optional) – the right bracket type, by default “\big]”

Methods

add_background_to_entries

add_brackets

Add the brackets to the Matrix mobject

get_brackets

Return the bracket mobjects

get_columns

Return columns of the matrix as VGroups

get_entries

Return the individual entries of the matrix

get_mob_matrix

Return the underlying mob matrix mobjects

get_rows

Return rows of the matrix as VGroups

matrix_to_mob_matrix

organize_mob_matrix

set_column_colors

Set individual colors for each columns of the matrix

set_row_colors

Set individual colors for each row of the matrix

Attributes

animate

Used to animate the application of a method.

depth

The depth of the mobject.

height

The height of the mobject.

width

The width of the mobject.

add_brackets(left='\\big[', right='\\big]')[source]

Add the brackets to the Matrix mobject

See Latex document for various bracket types.

Parameters
  • left (str, optional) – the left bracket, by default “\big[”

  • right (str, optional) – the right bracket, by default “\big]”

Returns

The current matrix object (self).

Return type

Matrix

get_brackets()[source]

Return the bracket mobjects

Returns

Each VGroup contains a bracket

Return type

List[VGroup]

get_columns()[source]

Return columns of the matrix as VGroups

Returns

Each VGroup contains a column of the matrix.

Return type

List[VGroup]

get_entries()[source]

Return the individual entries of the matrix

Returns

VGroup containing entries of the matrix

Return type

VGroup

get_mob_matrix()[source]

Return the underlying mob matrix mobjects

Returns

Each VGroup contains a row of the matrix.

Return type

List[VGroup]

get_rows()[source]

Return rows of the matrix as VGroups

Returns

Each VGroup contains a row of the matrix.

Return type

List[VGroup]

set_column_colors(*colors)[source]

Set individual colors for each columns of the matrix

Parameters

colors (str) – The list of colors; each color specified corresponds to a column.

Returns

The current matrix object (self).

Return type

Matrix

set_row_colors(*colors)[source]

Set individual colors for each row of the matrix

Parameters

colors (str) – The list of colors; each color specified corresponds to a row.

Returns

The current matrix object (self).

Return type

Matrix