Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Wrapped lines over 80 chars.
  • Loading branch information
pelson committed Aug 17, 2012
commit 456a72332352e4890b6f1323e6b7dfa3da4808fe
3 changes: 2 additions & 1 deletion lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def get_transform(self):
"""
if self._transform is None:
self._transform = IdentityTransform()
elif not isinstance(self._transform, Transform) and hasattr(self._transform, '_as_mpl_transform'):
elif (not isinstance(self._transform, Transform)
and hasattr(self._transform, '_as_mpl_transform')):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any point in checking for the _as_mpl_transform attribute? If it is not None, and it is not a Transform, and it can't be made into one, shouldn't it just raise an exception? Or is the idea that something not inheriting from Transform can still function as if it did?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was simply to not break anything else that was already passing something fruity. I think it might just get down to the point where the transform_path etc. methods are called and blow up if they don't exist on the thing in self._transform, though I am not entirely sure.

I'm not too fussed either way, but I am happy to be less generous and just try calling the _as_mpl_transform method, and if it doesn't exist, oh well... what is your preference?

self._transform = self._transform._as_mpl_transform(self.axes)
return self._transform

Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def get_transforms(self):

def get_offset_transform(self):
t = self._transOffset
if not isinstance(t, transforms.Transform) and hasattr(t, '_as_mpl_transform'):
if (not isinstance(t, transforms.Transform)
and hasattr(t, '_as_mpl_transform')):
t = t._as_mpl_transform(self.axes)
return t

Expand Down
9 changes: 7 additions & 2 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,15 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
line_colors.extend(color_values)
arrow_kw['color'] = cmap(norm(color_values[n]))

p = patches.FancyArrowPatch(arrow_tail, arrow_head, transform=transform, **arrow_kw)
p = patches.FancyArrowPatch(arrow_tail,
arrow_head,
transform=transform,
**arrow_kw)
axes.add_patch(p)

lc = mcollections.LineCollection(streamlines, transform=transform, **line_kw)
lc = mcollections.LineCollection(streamlines,
transform=transform,
**line_kw)
if use_multicolor_lines:
lc.set_array(np.asarray(line_colors))
lc.set_cmap(cmap)
Expand Down
10 changes: 7 additions & 3 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def _as_mpl_transform(self, axes):
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
# assert that the top transform of the line is the scale transform.
np.testing.assert_allclose(line.get_transform()._a.get_matrix(), mtrans.Affine2D().scale(10).get_matrix())
np.testing.assert_allclose(line.get_transform()._a.get_matrix(),
mtrans.Affine2D().scale(10).get_matrix())


@image_comparison(baseline_images=['pre_transform_data'])
Expand All @@ -78,10 +79,13 @@ def test_pre_transform_plotting():

ax.contourf(np.arange(48).reshape(6, 8), transform=times10 + ax.transData)

ax.pcolormesh(np.linspace(0, 4, 7), np.linspace(5.5, 8, 9), np.arange(48).reshape(6, 8),
ax.pcolormesh(np.linspace(0, 4, 7),
np.linspace(5.5, 8, 9),
np.arange(48).reshape(6, 8),
transform=times10 + ax.transData)

ax.scatter(np.linspace(0, 10), np.linspace(10, 0), transform=times10 + ax.transData)
ax.scatter(np.linspace(0, 10), np.linspace(10, 0),
transform=times10 + ax.transData)


x = np.linspace(8, 10, 20)
Expand Down