Introduction
A 2x2 matrix's numbers don't say much on their own — but watching what it does to a unit square makes rotation, scaling, shearing, and reflection immediately obvious. VisualizeMatrixAsLinearTransformation plots the unit square and its image after being multiplied by one matrix, or chains two matrices together to show a composite transformation, turning an abstract multiplication into a geometric before-and-after you can reason about directly.
Teaching Note
Visualizing linear transformations is essential for:
- Understanding how matrices warp, rotate, or scale coordinate spaces
- Identifying determinants geometrically through area changes of the square
- Analyzing the impact of composite transformations on data orientation
- Teaching fundamental concepts of basis changes and linear mappings
- Evaluating structural stability by examining transformation distortions
- Providing intuitive insights into PCA and other dimensionality reduction methods
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
two_by_two_matrix1required | | — | The first 2x2 matrix to visualize. Expected as a nested list or a 2D numpy.ndarray. |
two_by_two_matrix2 | | None | An optional second 2x2 matrix. If provided, the function visualizes the composition of matrix2 applied to the result of matrix1. Defaults to None. |
plot_with_grid | | False | Whether to show a coordinate grid on the plot. Defaults to False. |
show_labels | | True | Whether to show descriptive labels for the unit squares. Defaults to True. |
matrix1_color | | '#033dfc' | The color for the first transformed unit square. Defaults to '#033dfc'. |
matrix2_color | | '#03b1fc' | The color for the second transformed unit square (composed). Defaults to '#03b1fc'. |
x_min | | -5 | The minimum x-axis value for the plot. Defaults to -5. |
x_max | | 5 | The maximum x-axis value for the plot. Defaults to 5. |
y_min | | -5 | The minimum y-axis value for the plot. Defaults to -5. |
y_max | | 5 | The maximum y-axis value for the plot. Defaults to 5. |
Returns
None — the function renders an interactive Matplotlib plot.
Example
python
from analysistoolbox.linear_algebra import VisualizeMatrixAsLinearTransformation
import numpy as np
# Visualize a simple 45-degree rotation
theta = np.radians(45)
rotation = [[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]]
VisualizeMatrixAsLinearTransformation(rotation)