@@ -59,6 +59,8 @@ class Collection(artist.Artist, cm.ScalarMappable):
59
59
scalar mappable will be made to set the face colors.
60
60
"""
61
61
_offsets = np .array ([], np .float_ )
62
+ # _offsets must be a Nx2 array!
63
+ _offsets .shape = (0 , 2 )
62
64
_transOffset = transforms .IdentityTransform ()
63
65
_transforms = []
64
66
@@ -95,10 +97,11 @@ def __init__(self,
95
97
96
98
self ._uniform_offsets = None
97
99
self ._offsets = np .array ([], np .float_ )
100
+ # Force _offsets to be Nx2
101
+ self ._offsets .shape = (0 , 2 )
98
102
if offsets is not None :
99
103
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
102
105
if transOffset is not None :
103
106
self ._offsets = offsets
104
107
self ._transOffset = transOffset
@@ -148,13 +151,17 @@ def get_datalim(self, transData):
148
151
transOffset = self ._transOffset
149
152
offsets = self ._offsets
150
153
paths = self .get_paths ()
154
+
155
+
151
156
if not transform .is_affine :
152
157
paths = [transform .transform_path_non_affine (p ) for p in paths ]
153
158
transform = transform .get_affine ()
154
159
if not transOffset .is_affine :
155
160
offsets = transOffset .transform_non_affine (offsets )
156
161
transOffset = transOffset .get_affine ()
162
+
157
163
offsets = np .asarray (offsets , np .float_ )
164
+ offsets .shape = (- 1 , 2 ) # Make it Nx2
158
165
159
166
result = mpath .get_path_collection_extents (
160
167
transform .frozen (), paths , self .get_transforms (),
@@ -176,6 +183,7 @@ def _prepare_points(self):
176
183
offsets = self ._offsets
177
184
paths = self .get_paths ()
178
185
186
+
179
187
if self .have_units ():
180
188
paths = []
181
189
for path in self .get_paths ():
@@ -184,17 +192,19 @@ def _prepare_points(self):
184
192
xs = self .convert_xunits (xs )
185
193
ys = self .convert_yunits (ys )
186
194
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 ])
190
199
offsets = zip (xs , ys )
191
200
192
201
offsets = np .asarray (offsets , np .float_ )
202
+ offsets .shape = (- 1 , 2 ) # Make it Nx2
193
203
194
204
if not transform .is_affine :
195
205
paths = [transform .transform_path_non_affine (path ) for path in paths ]
196
206
transform = transform .get_affine ()
197
- if not transOffset .is_affine :
207
+ if not transOffset .is_affine :
198
208
offsets = transOffset .transform_non_affine (offsets )
199
209
transOffset = transOffset .get_affine ()
200
210
@@ -258,8 +268,7 @@ def set_offsets(self, offsets):
258
268
ACCEPTS: float or sequence of floats
259
269
"""
260
270
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
263
272
#This decision is based on how they are initialized above
264
273
if self ._uniform_offsets is None :
265
274
self ._offsets = offsets
@@ -1221,6 +1230,7 @@ def draw(self, renderer):
1221
1230
offsets = zip (xs , ys )
1222
1231
1223
1232
offsets = np .asarray (offsets , np .float_ )
1233
+ offsets .shape = (- 1 , 2 ) # Make it Nx2
1224
1234
1225
1235
self .update_scalarmappable ()
1226
1236
0 commit comments