# manim.scene.vector_space_scene.LinearTransformationScene¶

class LinearTransformationScene(include_background_plane=True, include_foreground_plane=True, background_plane_kwargs={'axis_config': {'color': '#888888'}, 'background_line_style': {'stroke_color': '#888888', 'stroke_width': 1}, 'color': '#888888'}, show_coordinates=False, show_basis_vectors=True, basis_vector_stroke_width=6, i_hat_color='#83C167', j_hat_color='#FC6255', leave_ghost_vectors=False, t_matrix=[[3, 0], [1, 2]], **kwargs)[source]

This scene contains special methods that make it especially suitable for showing Linear Transformations.

Methods

 add_background_mobject Adds the mobjects to the special list self.background_mobjects. add_foreground_mobject Adds the mobjects to the special list self.foreground_mobjects. add_moving_mobject Adds the mobject to the special list self.moving_mobject, and adds a property to the mobject called mobject.target, which keeps track of what the mobject will move to or become etc. add_special_mobjects Adds mobjects to a separate list that can be tracked, if these mobjects have some extra importance. add_title Adds a title, after scaling it, adding a background rectangle, moving it to the top and adding it to foreground_mobjects adding it as a local variable of self. add_transformable_label Method for creating, and animating the addition of a transformable label for the vector. add_transformable_mobject Adds the mobjects to the special list self.transformable_mobjects. add_unit_square Adds a unit square to the scene via self.get_unit_square. add_vector Adds a vector to the scene, and puts it in the special list self.moving_vectors. apply_function Applies the given function to each of the mobjects in self.transformable_mobjects, and plays the animation showing this. apply_inverse This method applies the linear transformation represented by the inverse of the passed matrix to the number plane, and each vector/similar mobject on it. apply_inverse_transpose Applies the inverse of the transformation represented by the given transposed matrix to the number plane and each vector/similar mobject on it. apply_matrix Applies the transformation represented by the given matrix to the number plane, and each vector/similar mobject on it. apply_nonlinear_transformation Applies the non-linear transformation represented by the given function to the number plane and each vector/similar mobject on it. apply_transposed_matrix Applies the transformation represented by the given transposed matrix to the number plane, and each vector/similar mobject on it. get_matrix_transformation Returns a function corresponding to the linear transformation represented by the matrix passed. get_moving_mobject_movement This method returns an animation that moves a mobject in “self.moving_mobjects” to its corresponding .target value. get_piece_movement This method returns an animation that moves an arbitrary mobject in “pieces” to its corresponding .target value. get_transformable_label_movement This method returns an animation that moves all labels in “self.transformable_labels” to its corresponding .target . get_transposed_matrix_transformation Returns a function corresponding to the linear transformation represented by the transposed matrix passed. get_unit_square Returns a unit square for the current NumberPlane. get_vector_movement This method returns an animation that moves a mobject in “self.moving_vectors” to its corresponding .target value. setup This is meant to be implemented by any scenes which are commonly subclassed, and have some common setup involved before the construct method is called. write_vector_coordinates Returns a column matrix indicating the vector coordinates, after writing them to the screen, and adding them to the special list self.foreground_mobjects

Attributes

 camera
add_background_mobject(*mobjects)[source]

Adds the mobjects to the special list self.background_mobjects.

Parameters

*mobjects (Mobject) – The mobjects to add to the list.

add_foreground_mobject(*mobjects)[source]

Adds the mobjects to the special list self.foreground_mobjects.

Parameters

*mobjects (Mobject) – The mobjects to add to the list

add_moving_mobject(mobject, target_mobject=None)[source]

Adds the mobject to the special list self.moving_mobject, and adds a property to the mobject called mobject.target, which keeps track of what the mobject will move to or become etc.

Parameters
• mobject (Mobject) – The mobjects to add to the list

• target_mobject (Mobject, optional) – What the moving_mobject goes to, etc.

add_special_mobjects(mob_list, *mobs_to_add)[source]

Adds mobjects to a separate list that can be tracked, if these mobjects have some extra importance.

Parameters
• mob_list (list) – The special list to which you want to add these mobjects.

add_title(title, scale_factor=1.5, animate=False)[source]

Adds a title, after scaling it, adding a background rectangle, moving it to the top and adding it to foreground_mobjects adding it as a local variable of self. Returns the Scene.

Parameters
• title (Union[str, MathTex, Tex]) – What the title should be.

• scale_factor (int, float, optional) – How much the title should be scaled by.

• animate (bool) – Whether or not to animate the addition.

Returns

The scene with the title added to it.

Return type

LinearTransformationScene

add_transformable_label(vector, label, transformation_name='L', new_label=None, **kwargs)[source]

Method for creating, and animating the addition of a transformable label for the vector.

Parameters
• vector (Vector) – The vector for which the label must be added.

• label (Union[MathTex, str]) – The MathTex/string of the label.

• transformation_name (Union[str, MathTex], optional) – The name to give the transformation as a label.

• new_label (Union[str, MathTex], optional) – What the label should display after a Linear Transformation

• **kwargs – Any valid keyword argument of get_vector_label

Returns

The MathTex of the label.

Return type

MathTex

add_transformable_mobject(*mobjects)[source]

Adds the mobjects to the special list self.transformable_mobjects.

Parameters

*mobjects (Mobject) – The mobjects to add to the list.

add_unit_square(animate=False, **kwargs)[source]

Adds a unit square to the scene via self.get_unit_square.

Parameters
• (bool) (animate) – Whether or not to animate the addition with DrawBorderThenFill.

• **kwargs – Any valid keyword arguments of self.get_unit_square()

Returns

The unit square.

Return type

Square

add_vector(vector, color='#FFFF00', **kwargs)[source]

Adds a vector to the scene, and puts it in the special list self.moving_vectors.

Parameters
• vector (Arrow,list,tuple,np.ndarray) – It can be a pre-made graphical vector, or the coordinates of one.

• color (str) – The string of the hex color of the vector. This is only taken into consideration if ‘vector’ is not an Arrow. Defaults to YELLOW.

• **kwargs – Any valid keyword argument of VectorScene.add_vector.

Returns

The arrow representing the vector.

Return type

Arrow

apply_function(function, added_anims=[], **kwargs)[source]

Applies the given function to each of the mobjects in self.transformable_mobjects, and plays the animation showing this.

Parameters
• function (Function) – The function that affects each point of each mobject in self.transformable_mobjects.

• added_anims (list, optional) – Any other animations that need to be played simultaneously with this.

• **kwargs – Any valid keyword argument of a self.play() call.

apply_inverse(matrix, **kwargs)[source]

This method applies the linear transformation represented by the inverse of the passed matrix to the number plane, and each vector/similar mobject on it.

Parameters
• matrix (np.ndarray, list, tuple) – The matrix whose inverse is to be applied.

• **kwargs – Any valid keyword argument of self.apply_matrix()

apply_inverse_transpose(t_matrix, **kwargs)[source]

Applies the inverse of the transformation represented by the given transposed matrix to the number plane and each vector/similar mobject on it.

Parameters
• matrix (np.ndarray, list, tuple) – The matrix.

• **kwargs – Any valid keyword argument of self.apply_transposed_matrix()

apply_matrix(matrix, **kwargs)[source]

Applies the transformation represented by the given matrix to the number plane, and each vector/similar mobject on it.

Parameters
• matrix (np.ndarray, list, tuple) – The matrix.

• **kwargs – Any valid keyword argument of self.apply_transposed_matrix()

apply_nonlinear_transformation(function, **kwargs)[source]

Applies the non-linear transformation represented by the given function to the number plane and each vector/similar mobject on it.

Parameters
• function (Function) – The function.

• **kwargs – Any valid keyword argument of self.apply_function()

apply_transposed_matrix(transposed_matrix, **kwargs)[source]

Applies the transformation represented by the given transposed matrix to the number plane, and each vector/similar mobject on it.

Parameters
• matrix (np.ndarray, list, tuple) – The matrix.

• **kwargs – Any valid keyword argument of self.apply_function()

get_matrix_transformation(matrix)[source]

Returns a function corresponding to the linear transformation represented by the matrix passed.

Parameters

matrix (np.ndarray, list, tuple) – The matrix.

get_moving_mobject_movement(func)[source]

This method returns an animation that moves a mobject in “self.moving_mobjects” to its corresponding .target value. func is a function that determines where the .target goes.

Parameters

func (function) – The function that determines where the .target of the moving mobject goes.

Returns

The animation of the movement.

Return type

Animation

get_piece_movement(pieces)[source]

This method returns an animation that moves an arbitrary mobject in “pieces” to its corresponding .target value. If self.leave_ghost_vectors is True, ghosts of the original positions/mobjects are left on screen

Parameters

pieces (list, tuple, np.array) – The pieces for which the movement must be shown.

Returns

The animation of the movement.

Return type

Animation

get_transformable_label_movement()[source]

This method returns an animation that moves all labels in “self.transformable_labels” to its corresponding .target .

Returns

The animation of the movement.

Return type

Animation

get_transposed_matrix_transformation(transposed_matrix)[source]

Returns a function corresponding to the linear transformation represented by the transposed matrix passed.

Parameters

matrix (np.ndarray, list, tuple) – The matrix.

get_unit_square(color='#FFFF00', opacity=0.3, stroke_width=3)[source]

Returns a unit square for the current NumberPlane.

Parameters
• color (str, optional) – The string of the hex color code of the color wanted.

• opacity (float, int, optional) – The opacity of the square

• stroke_width (int, float, optional) – The stroke_width in pixels of the border of the square

Returns

Return type

Square

get_vector_movement(func)[source]

This method returns an animation that moves a mobject in “self.moving_vectors” to its corresponding .target value. func is a function that determines where the .target goes.

Parameters

func (function) – The function that determines where the .target of the moving mobject goes.

Returns

The animation of the movement.

Return type

Animation

setup()[source]

This is meant to be implemented by any scenes which are commonly subclassed, and have some common setup involved before the construct method is called.

write_vector_coordinates(vector, **kwargs)[source]

Returns a column matrix indicating the vector coordinates, after writing them to the screen, and adding them to the special list self.foreground_mobjects

Parameters
• vector (Arrow) – The arrow representing the vector.

• **kwargs – Any valid keyword arguments of VectorScene.write_vector_coordinates

Returns

The column matrix representing the vector.

Return type

Matrix