Skip to content
Merged
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
Next Next commit
Since most transformation code assumes 2d input, convert the values t…
…o a 2d array before applying any transforms and then convert the result back to the original shape.
  • Loading branch information
maxalbert committed Dec 4, 2014
commit 7d35c5edfda464bc6944d355bcf943edce994089
32 changes: 29 additions & 3 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,30 @@ def transform(self, values):

Accepts a numpy array of shape (N x :attr:`input_dims`) and
returns a numpy array of shape (N x :attr:`output_dims`).

Alternatively, accepts a numpy array of length :attr:`input_dims`
and returns a numpy array of length :attr:`output_dims`.
"""
return self.transform_affine(self.transform_non_affine(values))
# Ensure that values is a 2d array (but remember whether
# we started with a 1d or 2d array).
values = np.asanyarray(values)
ndim = values.ndim
values = values.reshape((-1, self.input_dims))

# Transform the values
res = self.transform_affine(self.transform_non_affine(values))

# Convert the result back to the shape of the input values.
if ndim == 1:
return res.reshape(-1)
elif ndim == 2:
return res
else:
raise ValueError(
"Input values must have shape (N x {dims}) "
"or ({dims}).".format(dims=self.input_dims))

return res

def transform_affine(self, values):
"""
Expand All @@ -1302,6 +1324,9 @@ def transform_affine(self, values):

Accepts a numpy array of shape (N x :attr:`input_dims`) and
returns a numpy array of shape (N x :attr:`output_dims`).

Alternatively, accepts a numpy array of length :attr:`input_dims`
and returns a numpy array of length :attr:`output_dims`.
"""
return self.get_affine().transform(values)

Expand All @@ -1318,6 +1343,9 @@ def transform_non_affine(self, values):

Accepts a numpy array of shape (N x :attr:`input_dims`) and
returns a numpy array of shape (N x :attr:`output_dims`).

Alternatively, accepts a numpy array of length :attr:`input_dims`
and returns a numpy array of length :attr:`output_dims`.
"""
return values

Expand Down Expand Up @@ -2040,8 +2068,6 @@ def __repr__(self):
return "BlendedGenericTransform(%s,%s)" % (self._x, self._y)

def transform_non_affine(self, points):
points = np.asanyarray(points).reshape((-1, 2))

if self._x.is_affine and self._y.is_affine:
return points
x = self._x
Expand Down