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

Skip to content

Commit c3ec92e

Browse files
committed
Merge pull request matplotlib#1790 from pelson/set_transform_on_artist
Fixes problem raised in matplotlib#1431 (```get_transform``` should not affect ```is_transform_set```)
2 parents b25d275 + 92a0843 commit c3ec92e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/matplotlib/artist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def get_transform(self):
240240
instance used by this artist.
241241
"""
242242
if self._transform is None:
243-
self.set_transform(IdentityTransform())
243+
self._transform = IdentityTransform()
244244
elif (not isinstance(self._transform, Transform)
245245
and hasattr(self._transform, '_as_mpl_transform')):
246246
self._transform = self._transform._as_mpl_transform(self.axes)

lib/matplotlib/tests/test_artist.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,38 @@ def test_patch_transform_of_none():
1818
ax.set_xlim([1, 3])
1919
ax.set_ylim([1, 3])
2020

21-
#draw an ellipse over data coord (2,2) by specifying device coords
21+
# Draw an ellipse over data coord (2,2) by specifying device coords.
2222
xy_data = (2, 2)
2323
xy_pix = ax.transData.transform_point(xy_data)
2424

25-
# not providing a transform of None puts the ellipse in data coordinates
25+
# Not providing a transform of None puts the ellipse in data coordinates .
2626
e = mpatches.Ellipse(xy_data, width=1, height=1, fc='yellow', alpha=0.5)
2727
ax.add_patch(e)
2828
assert e._transform == ax.transData
2929

30-
# providing a transform of None puts the ellipse in device coordinates
30+
# Providing a transform of None puts the ellipse in device coordinates.
3131
e = mpatches.Ellipse(xy_pix, width=120, height=120, fc='coral',
3232
transform=None, alpha=0.5)
33+
assert e.is_transform_set() is True
3334
ax.add_patch(e)
3435
assert isinstance(e._transform, mtrans.IdentityTransform)
3536

36-
# providing an IdentityTransform puts the ellipse in device coordinates
37+
# Providing an IdentityTransform puts the ellipse in device coordinates.
3738
e = mpatches.Ellipse(xy_pix, width=100, height=100,
3839
transform=mtrans.IdentityTransform(), alpha=0.5)
3940
ax.add_patch(e)
4041
assert isinstance(e._transform, mtrans.IdentityTransform)
42+
43+
# Not providing a transform, and then subsequently "get_transform" should
44+
# not mean that "is_transform_set".
45+
e = mpatches.Ellipse(xy_pix, width=120, height=120, fc='coral',
46+
alpha=0.5)
47+
intermediate_transform = e.get_transform()
48+
assert e.is_transform_set() is False
49+
ax.add_patch(e)
50+
assert e.get_transform() != intermediate_transform
51+
assert e.is_transform_set() is True
52+
assert e._transform == ax.transData
4153

4254

4355
@cleanup

0 commit comments

Comments
 (0)