Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dbe074

Browse files
committed
Added appropriate change logs for new transform mechanims, fixed a bug (and updated appropriate test).
1 parent 45f234f commit 8dbe074

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

doc/api/api_changes.rst

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,53 @@ Changes in 1.2.x
7272
original keyword arguments will override any value provided by
7373
*capthick*.
7474

75-
* Aritsts no longer have ``x_isdata`` or ``y_isdata`` attributes. Instead
75+
* Transform subclassing behaviour is now subtly changed. If your transform
76+
implements a non-affine transformation, then it should override the
77+
``transform_non_affine`` method, rather than the generic ``transform`` method.
78+
Previously transforms would define ``transform`` and then copy the
79+
method into ``transform_non_affine``:
80+
81+
class MyTransform(mtrans.Transform):
82+
def transform(self, xy):
83+
...
84+
transform_non_affine = transform
85+
86+
This approach will no longer function correctly and should be changed to:
87+
88+
class MyTransform(mtrans.Transform):
89+
def transform_non_affine(self, xy):
90+
...
91+
92+
* Artists no longer have ``x_isdata`` or ``y_isdata`` attributes; instead
7693
any artist's transform can be interrogated with
77-
``artist_instance.get_transform().is_data(ax.transData)``
94+
``artist_instance.get_transform().contains_branch(ax.transData)``
95+
96+
* Lines added to an axes now take into account their transform when updating the
97+
data and view limits. This means transforms can now be used as a pre-transform.
98+
For instance:
99+
100+
>>> import matplotlib.pyplot as plt
101+
>>> import matplotlib.transforms as mtrans
102+
>>> ax = plt.axes()
103+
>>> ax.plot(range(10), transform=mtrans.Affine2D().scale(10) + ax.transData)
104+
>>> print(ax.viewLim)
105+
Bbox('array([[ 0., 0.],\n [ 90., 90.]])')
106+
107+
* One can now easily get a transform which goes from one transform's coordinate system
108+
to another, in an optimized way, using the new subtract method on a transform. For instance,
109+
to go from data coordinates to axes coordinates::
110+
111+
>>> import matplotlib.pyplot as plt
112+
>>> ax = plt.axes()
113+
>>> data2ax = ax.transData - ax.transAxes
114+
>>> print(ax.transData.depth, ax.transAxes.depth)
115+
3, 1
116+
>>> print(data2ax.depth)
117+
2
118+
119+
for versions before 2.0 this could only be achieved in a sub-optimal way, using
120+
``ax.transData + ax.transAxes.inverted()`` (depth is a new concept, but had it existed
121+
it would return 4 for this example).
78122

79123
Changes in 1.1.x
80124
================

lib/matplotlib/tests/test_transforms.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,11 @@ def test_transform_shortcuts(self):
240240
self.assertEqual(self.stack1 - self.stack2_subset, self.ta1)
241241
self.assertEqual(self.stack2 - self.stack2_subset, self.ta1)
242242

243-
# check that we cannot find a chain from the subset back to the superset
244-
# (since the inverse of the Transform is not defined.)
245-
assert_raises(ValueError, self.stack2_subset.__sub__, self.stack2)
243+
assert_equal((self.stack2_subset - self.stack2),
244+
self.ta1.inverted(),
245+
)
246+
assert_equal((self.stack2_subset - self.stack2).depth, 1)
247+
246248
assert_raises(ValueError, self.stack1.__sub__, self.stack2)
247249

248250
aff1 = self.ta1 + (self.ta2 + self.ta3)

lib/matplotlib/transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,8 @@ def __sub__(self, other):
11811181
if sub_tree == other:
11821182
return remainder
11831183

1184-
for remainder, sub_tree in self._iter_break_from_left_to_right():
1185-
if sub_tree == other:
1184+
for remainder, sub_tree in other._iter_break_from_left_to_right():
1185+
if sub_tree == self:
11861186
if not remainder.has_inverse:
11871187
raise ValueError("The shortcut cannot be computed since "
11881188
"other's transform includes a non-invertable component.")

0 commit comments

Comments
 (0)