Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit76efb2a

Browse files
committed
matrix_transform replaces _affine_transform and divides by w
1 parent06cf46f commit76efb2a

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

‎lib/matplotlib/transforms.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,40 @@ def strrepr(x): return repr(x) if isinstance(x, str) else str(x)
8181
+")")
8282

8383

84+
defmatrix_transform(vertices,mtx):
85+
"""
86+
Transforms a vertex or set of vertices with a matrix mtx of
87+
one dimension higher.
88+
89+
Parameters
90+
----------
91+
vertices : n-element array or (m, n) array, with m vertices
92+
mtx : (n+1, n+1) matrix
93+
"""
94+
values=np.asanyarray(vertices)
95+
_,input_dims=mtx.shape
96+
input_dims=input_dims-1
97+
98+
if (len(values.shape)==1):
99+
# single point
100+
if (values.shape== (input_dims,)):
101+
point=mtx.dot(np.append(values, [1]))
102+
point=point/point[-1]
103+
returnpoint[:input_dims]
104+
raiseRuntimeError("Invalid vertices provided to transform")
105+
106+
# multiple points
107+
if (len(values.shape)==2andvalues.shape[1]==input_dims):
108+
points=np.hstack((values,np.ones((values.shape[0],1))))
109+
points=np.dot(mtx,points.T).T
110+
last_coords=points[:,-1]
111+
points=points/last_coords[:,np.newaxis]
112+
returnpoints[:, :-1]
113+
114+
raiseValueError("Dimensions of input must match the input dimensions of "
115+
"the transform")
116+
117+
84118
classTransformNode:
85119
"""
86120
The base class for anything that participates in the transform tree
@@ -1873,34 +1907,12 @@ def to_values(self):
18731907
mtx=self.get_matrix()
18741908
returntuple(mtx[:self.input_dims].swapaxes(0,1).flat)
18751909

1876-
def_affine_transform(self,vertices,mtx):
1877-
"""
1878-
Default implementation of affine_transform if a C implementation isn't
1879-
available
1880-
"""
1881-
values=np.asanyarray(vertices)
1882-
1883-
if (len(values.shape)==1):
1884-
# single point
1885-
if (values.shape== (self.input_dims,)):
1886-
returnmtx.dot(np.append(values, [1]))[:self.input_dims]
1887-
raiseRuntimeError("Invalid vertices provided to transform")
1888-
1889-
# multiple points
1890-
if (len(values.shape)==2andvalues.shape[1]==self.input_dims):
1891-
homogeneous=np.hstack((values,np.ones((values.shape[0],1))))
1892-
returnnp.dot(mtx,homogeneous.T).T[:, :-1]
1893-
1894-
raiseValueError("Dimensions of input must match the input dimensions of "
1895-
"the transform")
1896-
18971910
@_api.rename_parameter("3.8","points","values")
18981911
deftransform_affine(self,values):
18991912
mtx=self.get_matrix()
19001913

19011914
# Default to python implementation if C implementation isn't available
1902-
transform_fn= (affine_transformifself.input_dims<=2
1903-
elseself._affine_transform)
1915+
transform_fn= (affine_transformifself.input_dims<=2elsematrix_transform)
19041916

19051917
ifisinstance(values,np.ma.MaskedArray):
19061918
tpoints=transform_fn(values.data,mtx)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp