# Applying a Transformation Matrix to Entire Graphics Including Axes in Mathematica

I'm working with a Graphics object in Mathematica and I want to apply a transformation matrix to the entire object, including its axes.

Here's a simplified version of my code:

graphics=Graphics[{}, Axes -> True]
matrix={{1/Sqrt[2], -(1/Sqrt[2])}, {1/Sqrt[2], 1/Sqrt[2]}}
TheNeededFunctionThatTransformsGraphicsByMatrix[graphics,matrix] (* Should output a rotated axes. *)


Is there such a function in Mathematica?

• ViewMatrix reference.wolfram.com/legacy/language/v13/ref/… Commented Dec 30, 2023 at 9:33
• Or simply Rotate[Graphics[{}, Axes -> True], \[Pi]/4]. Commented Dec 30, 2023 at 9:43
• Thanks! ViewMatrix seems to be a option that only can be applied to a Graphics3D object. Commented Dec 30, 2023 at 9:55
• Do you need the output to be a Graphics[...] expression? Will it be OK to transform the graphics to an Image[...]? Commented Dec 30, 2023 at 10:15
• @benjaminchanming: In 3D you can draw to the plane z=0 as if in 2D and then you can use ViewMatrix. Commented Dec 30, 2023 at 11:38

Using ImagePerspectiveTransformation:

... and the matrix from the docs:

g = Graphics[{Darker@Cyan, RegularPolygon[5]}
, Axes -> True
, AxesStyle -> Yellow
, Background -> Black
, PlotRange -> All
, Frame -> True
]

matrix = {{1, 1/3, 0}, {1/3, 1, 0}, {0, 1/2, 1}}
ImagePerspectiveTransformation[Rasterize@g, matrix]


Rotate[Graphics[{}, Axes -> True], π/4]

• Rotate works! But is there a more general function that do any linear transformation represented by a matrix? Commented Dec 30, 2023 at 9:56