8000 Add skew() and skew_deg() to Affine2D. · matplotlib/matplotlib@c5cdcbf · GitHub
[go: up one dir, main page]

Skip to content

Commit c5cdcbf

Browse files
committed
Add skew() and skew_deg() to Affine2D.
These set up skew transforms, which can be viewed as indpendantly rotating the X and Y axes.
1 parent d316904 commit c5cdcbf

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/matplotlib/transforms.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,39 @@ def scale(self, sx, sy=None):
18731873
self.invalidate()
18741874
return self
18751875

1876+
def skew(self, xAxisRot, yAxisRot):
1877+
"""
1878+
Adds a skew in place.
1879+
1880+
*xAxisRot* and *yAxisRot* are the rotations of the *x*- and
1881+
*y*-axes, respectively, in radians.
1882+
1883+
Returns *self*, so this method can easily be chained with more
1884+
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
1885+
and :meth:`scale`.
1886+
"""
1887+
rotX = np.tan(xAxisRot)
1888+
rotY = np.tan(yAxisRot)
1889+
skew_mtx = np.array(
1890+
[[1.0, rotY, 0.0], [rotX, 1.0, 0.0], [0.0, 0.0, 1.0]],
1891+
np.float_)
1892+
self._mtx = np.dot(skew_mtx, self._mtx)
1893+
self.invalidate()
1894+
return self
1895+
1896+
def skew_deg(self, xAxisRot, yAxisRot):
1897+
"""
1898+
Adds a skew in place.
1899+
1900+
*xAxisRot* and *yAxisRot* are the rotations of the *x*- and
1901+
*y*-axes, respectively, in degrees.
1902+
1903+
Returns *self*, so this method can easily be chained with more
1904+
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
1905+
and :meth:`scale`.
1906+
"""
1907+
return self.skew(np.deg2rad(xAxisRot), np.deg2rad(yAxisRot))
1908+
18761909
def _get_is_separable(self):
18771910
mtx = self.get_matrix()
18781911
return mtx[0, 1] == 0.0 and mtx[1, 0] == 0.0

0 commit comments

Comments
 (0)
0