Permalink
Browse files

Added test for pre-transforming some plot types.

  • Loading branch information...
1 parent 5df279d commit 7d6fced056f619cd12c84492586b0fbb77cffd44 @pelson committed Mar 2, 2012
View
@@ -3,7 +3,7 @@
import matplotlib
import matplotlib.cbook as cbook
from matplotlib import docstring, rcParams
-from transforms import Bbox, IdentityTransform, TransformedBbox,
+from transforms import Bbox, IdentityTransform, TransformedBbox, \
TransformedPath, Transform
from path import Path
View
@@ -6489,7 +6489,7 @@ def stackplot(self, x, *args, **kwargs):
def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
- minlength=0.1):
+ minlength=0.1, transform=None):
if not self._hold: self.cla()
lines = mstream.streamplot(self, x, y, u, v,
density=density,
@@ -6499,7 +6499,8 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
norm=norm,
arrowsize=arrowsize,
arrowstyle=arrowstyle,
- minlength=minlength)
+ minlength=minlength,
+ transform=transform)
return lines
streamplot.__doc__ = mstream.streamplot.__doc__
View
@@ -408,10 +408,11 @@ def __init__(self, ax, *args, **kw):
self.width = kw.pop('width', None)
self.color = kw.pop('color', 'k')
self.pivot = kw.pop('pivot', 'tail')
+ self.transform = kw.pop('transform', ax.transData)
kw.setdefault('facecolors', self.color)
kw.setdefault('linewidths', (0,))
collections.PolyCollection.__init__(self, [], offsets=self.XY,
- transOffset=ax.transData,
+ transOffset=self.transform,
closed=False,
**kw)
self.polykw = kw
@@ -529,8 +530,6 @@ def _angles_lengths(self, U, V, eps=1):
lengths = np.absolute(dxy[:,0] + dxy[:,1]*1j) / eps
return angles, lengths
-
-
def _make_verts(self, U, V):
uv = (U+V*1j)
if self.angles == 'xy' and self.scale_units == 'xy':
@@ -592,7 +591,6 @@ def _make_verts(self, U, V):
return XY
-
def _h_arrows(self, length):
""" length is in arrow width units """
# It might be possible to streamline the code
@@ -824,6 +822,7 @@ def __init__(self, ax, *args, **kw):
self.barb_increments = kw.pop('barb_increments', dict())
self.rounding = kw.pop('rounding', True)
self.flip = kw.pop('flip_barb', False)
+ transform = kw.pop('transform', ax.transData)
#Flagcolor and and barbcolor provide convenience parameters for setting
#the facecolor and edgecolor, respectively, of the barb polygon. We
@@ -851,7 +850,7 @@ def __init__(self, ax, *args, **kw):
#Make a collection
barb_size = self._length**2 / 4 #Empirically determined
collections.PolyCollection.__init__(self, [], (barb_size,), offsets=xy,
- transOffset=ax.transData, **kw)
+ transOffset=transform, **kw)
self.set_transform(transforms.IdentityTransform())
self.set_UVC(u, v, c)
@@ -14,7 +14,7 @@
def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
- minlength=0.1):
+ minlength=0.1, transform=None):
"""Draws streamlines of a vector flow.
Parameters
@@ -138,10 +138,10 @@ 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, **arrow_kw)
+ p = patches.FancyArrowPatch(arrow_tail, arrow_head, transform=transform, **arrow_kw)
axes.add_patch(p)
- lc = mcollections.LineCollection(streamlines, **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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 7d6fced

Please sign in to comment.