@@ -59,6 +59,8 @@ class Collection(artist.Artist, cm.ScalarMappable):
5959 scalar mappable will be made to set the face colors.
6060 """
6161 _offsets = np .array ([], np .float_ )
62+ # _offsets must be a Nx2 array!
63+ _offsets .shape = (0 , 2 )
6264 _transOffset = transforms .IdentityTransform ()
6365 _transforms = []
6466
@@ -95,10 +97,11 @@ def __init__(self,
9597
9698 self ._uniform_offsets = None
9799 self ._offsets = np .array ([], np .float_ )
100+ # Force _offsets to be Nx2
101+ self ._offsets .shape = (0 , 2 )
98102 if offsets is not None :
99103 offsets = np .asarray (offsets )
100- if len (offsets .shape ) == 1 :
101- offsets = offsets [np .newaxis ,:] # Make it Nx2.
104+ offsets .shape = (- 1 , 2 ) # Make it Nx2
102105 if transOffset is not None :
103106 self ._offsets = offsets
104107 self ._transOffset = transOffset
@@ -148,13 +151,17 @@ def get_datalim(self, transData):
148151 transOffset = self ._transOffset
149152 offsets = self ._offsets
150153 paths = self .get_paths ()
154+
155+
151156 if not transform .is_affine :
152157 paths = [transform .transform_path_non_affine (p ) for p in paths ]
153158 transform = transform .get_affine ()
154159 if not transOffset .is_affine :
155160 offsets = transOffset .transform_non_affine (offsets )
156161 transOffset = transOffset .get_affine ()
162+
157163 offsets = np .asarray (offsets , np .float_ )
164+ offsets .shape = (- 1 , 2 ) # Make it Nx2
158165
159166 result = mpath .get_path_collection_extents (
160167 transform .frozen (), paths , self .get_transforms (),
@@ -176,6 +183,7 @@ def _prepare_points(self):
176183 offsets = self ._offsets
177184 paths = self .get_paths ()
178185
186+
179187 if self .have_units ():
180188 paths = []
181189 for path in self .get_paths ():
@@ -184,17 +192,19 @@ def _prepare_points(self):
184192 xs = self .convert_xunits (xs )
185193 ys = self .convert_yunits (ys )
186194 paths .append (mpath .Path (zip (xs , ys ), path .codes ))
187- if len (self ._offsets ):
188- xs = self .convert_xunits (self ._offsets [:,0 ])
189- ys = self .convert_yunits (self ._offsets [:,1 ])
195+
196+ if offsets .size > 0 :
197+ xs = self .convert_xunits (offsets [:,0 ])
198+ ys = self .convert_yunits (offsets [:,1 ])
190199 offsets = zip (xs , ys )
191200
192201 offsets = np .asarray (offsets , np .float_ )
202+ offsets .shape = (- 1 , 2 ) # Make it Nx2
193203
194204 if not transform .is_affine :
195205 paths = [transform .transform_path_non_affine (path ) for path in paths ]
196206 transform = transform .get_affine ()
197- if not transOffset .is_affine :
207+ if not transOffset .is_affine :
198208 offsets = transOffset .transform_non_affine (offsets )
199209 transOffset = transOffset .get_affine ()
200210
@@ -258,8 +268,7 @@ def set_offsets(self, offsets):
258268 ACCEPTS: float or sequence of floats
259269 """
260270 offsets = np .asarray (offsets , np .float_ )
261- if len (offsets .shape ) == 1 :
262- offsets = offsets [np .newaxis ,:] # Make it Nx2.
271+ offsets .shape = (- 1 , 2 ) # Make it Nx2
263272 #This decision is based on how they are initialized above
264273 if self ._uniform_offsets is None :
265274 self ._offsets = offsets
@@ -1221,6 +1230,7 @@ def draw(self, renderer):
12211230 offsets = zip (xs , ys )
12221231
12231232 offsets = np .asarray (offsets , np .float_ )
1233+ offsets .shape = (- 1 , 2 ) # Make it Nx2
12241234
12251235 self .update_scalarmappable ()
12261236
0 commit comments