Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dd3d68e

Browse filesBrowse files
committed
Merge pull request #1431 from pelson/transform_none
Fixed transform=None behaviour on Artists.
2 parents 93e16e7 + 1756352 commit dd3d68e
Copy full SHA for dd3d68e

File tree

Expand file treeCollapse file tree

4 files changed

+89
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+89
-2
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ def tk_window_focus():
10661066

10671067
default_test_modules = [
10681068
'matplotlib.tests.test_agg',
1069+
'matplotlib.tests.test_artist',
10691070
'matplotlib.tests.test_axes',
10701071
'matplotlib.tests.test_backend_svg',
10711072
'matplotlib.tests.test_backend_pgf',

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def set_transform(self, t):
231231
ACCEPTS: :class:`~matplotlib.transforms.Transform` instance
232232
"""
233233
self._transform = t
234-
self._transformSet = t is not None
234+
self._transformSet = True
235235
self.pchanged()
236236

237237
def get_transform(self):
@@ -240,7 +240,7 @@ def get_transform(self):
240240
instance used by this artist.
241241
"""
242242
if self._transform is None:
243-
self._transform = IdentityTransform()
243+
self.set_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)
@@ -663,6 +663,7 @@ def update(self, props):
663663
store = self.eventson
664664
self.eventson = False
665665
changed = False
666+
666667
for k, v in props.iteritems():
667668
func = getattr(self, 'set_' + k, None)
668669
if func is None or not callable(func):

‎lib/matplotlib/streamplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/streamplot.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
6565
mask = StreamMask(density)
6666
dmap = DomainMap(grid, mask)
6767

68+
# default to data coordinates
69+
if transform is None:
70+
transform = axes.transData
71+
6872
if color is None:
6973
color = axes._get_lines.color_cycle.next()
7074

‎lib/matplotlib/tests/test_artist.py

Copy file name to clipboard
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from __future__ import print_function
2+
3+
from matplotlib.testing.decorators import cleanup
4+
5+
import matplotlib.pyplot as plt
6+
7+
import matplotlib.patches as mpatches
8+
import matplotlib.transforms as mtrans
9+
import matplotlib.collections as mcollections
10+
11+
12+
@cleanup
13+
def test_patch_transform_of_none():
14+
# tests the behaviour of patches added to an Axes with various transform
15+
# specifications
16+
17+
ax = plt.axes()
18+
ax.set_xlim([1, 3])
19+
ax.set_ylim([1, 3])
20+
21+
#draw an ellipse over data coord (2,2) by specifying device coords
22+
xy_data = (2, 2)
23+
xy_pix = ax.transData.transform_point(xy_data)
24+
25+
# not providing a transform of None puts the ellipse in data coordinates
26+
e = mpatches.Ellipse(xy_data, width=1, height=1, fc='yellow', alpha=0.5)
27+
ax.add_patch(e)
28+
assert e._transform == ax.transData
29+
30+
# providing a transform of None puts the ellipse in device coordinates
31+
e = mpatches.Ellipse(xy_pix, width=120, height=120, fc='coral',
32+
transform=None, alpha=0.5)
33+
ax.add_patch(e)
34+
assert isinstance(e._transform, mtrans.IdentityTransform)
35+
36+
# providing an IdentityTransform puts the ellipse in device coordinates
37+
e = mpatches.Ellipse(xy_pix, width=100, height=100,
38+
transform=mtrans.IdentityTransform(), alpha=0.5)
39+
ax.add_patch(e)
40+
assert isinstance(e._transform, mtrans.IdentityTransform)
41+
42+
43+
@cleanup
44+
def test_collection_transform_of_none():
45+
# tests the behaviour of collections added to an Axes with various
46+
# transform specifications
47+
48+
ax = plt.axes()
49+
ax.set_xlim([1, 3])
50+
ax.set_ylim([1, 3])
51+
52+
#draw an ellipse over data coord (2,2) by specifying device coords
53+
xy_data = (2, 2)
54+
xy_pix = ax.transData.transform_point(xy_data)
55+
56+
# not providing a transform of None puts the ellipse in data coordinates
57+
e = mpatches.Ellipse(xy_data, width=1, height=1)
58+
c = mcollections.PatchCollection([e], facecolor='yellow', alpha=0.5)
59+
ax.add_collection(c)
60+
# the collection should be in data coordinates
61+
assert c.get_offset_transform() + c.get_transform() == ax.transData
62+
63+
# providing a transform of None puts the ellipse in device coordinates
64+
e = mpatches.Ellipse(xy_pix, width=120, height=120)
65+
c = mcollections.PatchCollection([e], facecolor='coral',
66+
alpha=0.5)
67+
c.set_transform(None)
68+
ax.add_collection(c)
69+
assert isinstance(c.get_transform(), mtrans.IdentityTransform)
70+
71+
# providing an IdentityTransform puts the ellipse in device coordinates
72+
e = mpatches.Ellipse(xy_pix, width=100, height=100)
73+
c = mcollections.PatchCollection([e], transform=mtrans.IdentityTransform(),
74+
alpha=0.5)
75+
ax.add_collection(c)
76+
assert isinstance(c._transOffset, mtrans.IdentityTransform)
77+
78+
79+
if __name__=='__main__':
80+
import nose
81+
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.