## [Matplotlib-users] PolyCollection and transforms

 [Matplotlib-users] PolyCollection and transforms From: Mika, David P (GE, Research) - 2007-11-29 18:50:52 Attachments: Message as HTML ```I am trying to animate the movement of a polygon and thought a sound approach would be to in a loop where I redraw after altering the offsets value. However I seem to not be able to scale the polygon correctly. Here is an example of only trying to place a polygon (square) at 1,1. You can see the translation is correct, but the scaling is wrong--the polygon is only about a pixel high & wide. Dave ------------------------------------------------------------------------ ---------- import pylab as P from matplotlib import collections, axes, transforms import matplotlib.numerix as N fig =3D P.figure() a =3D fig.add_subplot(1,1,1) verts =3D N.array([[0,0],[1,0],[1,1],[0,1]]) offsets =3D [[1,1]] col =3D collections.PolyCollection([verts], offsets=3Doffsets, transOffset=3Da.transData) a.add_collection(col) trans =3D transforms.scale_transform(transforms.Value(1),transforms.Value(1)) col.set_transform(trans)=20 a.set_xlim([-5,5]) a.set_ylim([-5,5]) P.show() ------------------------------------------------------------------------ ---------- ```

 [Matplotlib-users] PolyCollection and transforms From: Mika, David P (GE, Research) - 2007-11-29 18:50:52 Attachments: Message as HTML ```I am trying to animate the movement of a polygon and thought a sound approach would be to in a loop where I redraw after altering the offsets value. However I seem to not be able to scale the polygon correctly. Here is an example of only trying to place a polygon (square) at 1,1. You can see the translation is correct, but the scaling is wrong--the polygon is only about a pixel high & wide. Dave ------------------------------------------------------------------------ ---------- import pylab as P from matplotlib import collections, axes, transforms import matplotlib.numerix as N fig =3D P.figure() a =3D fig.add_subplot(1,1,1) verts =3D N.array([[0,0],[1,0],[1,1],[0,1]]) offsets =3D [[1,1]] col =3D collections.PolyCollection([verts], offsets=3Doffsets, transOffset=3Da.transData) a.add_collection(col) trans =3D transforms.scale_transform(transforms.Value(1),transforms.Value(1)) col.set_transform(trans)=20 a.set_xlim([-5,5]) a.set_ylim([-5,5]) P.show() ------------------------------------------------------------------------ ---------- ```