@@ -73,16 +73,14 @@ def get_dir_vector(zdir):
73
73
74
74
75
75
def _array_split (arr , indices_or_sections , remove_empty = False ):
76
- """Fix numpy.split to preserve the dimension of empty subarrays.
77
- """
78
-
76
+ """Fix numpy.split to preserve the dimension of empty subarrays."""
79
77
arr_chunks = np .split (arr , indices_or_sections )
80
78
81
79
if arr_chunks [- 1 ].size == 0 :
82
-
83
80
if not remove_empty :
84
81
# Preserve the 2D dimensionality the last chunk that can be empty
85
82
# (numpy <=1.10 replaces empty chunks by a 1D empty array)
83
+
86
84
# TODO: The following can be removed when
87
85
# support for numpy <=1.10 is dropped.
88
86
arr_chunks [- 1 ] = np .empty (shape = (0 , arr .shape [1 ]), dtype = arr .dtype )
@@ -169,8 +167,8 @@ def set_3d_properties(self, zs=0, zdir='z'):
169
167
@artist .allow_rasterization
170
168
def draw (self , renderer ):
171
169
xs3d , ys3d , zs3d = self ._verts3d
172
- xyz = proj3d .proj_transform (xs3d , ys3d , zs3d , renderer .M )
173
- self .set_data (xyz [ 0 ], xyz [ 1 ] )
170
+ xs , ys , zs = proj3d .proj_transform (xs3d , ys3d , zs3d , renderer .M )
171
+ self .set_data (xs , ys )
174
172
lines .Line2D .draw (self , renderer )
175
173
self .stale = False
176
174
@@ -184,9 +182,7 @@ def line_2d_to_3d(line, zs=0, zdir='z'):
184
182
185
183
def path_to_3d_segment (path , zs = 0 , zdir = 'z' ):
186
184
"""Convert a path to a 3D segment."""
187
- # Pre allocate memory
188
185
seg3d = np .ones ((3 , len (path )))
189
-
190
186
# Works both if zs is and array and a scalar
191
187
seg3d [2 , :] *= zs
192
188
@@ -208,10 +204,7 @@ def paths_to_3d_segments(paths, zs=0, zdir='z'):
208
204
209
205
def path_to_3d_segment_with_codes (path , zs = 0 , zdir = 'z' ):
210
206
"""Convert a path to a 3D segment with path codes."""
211
- # Pre allocate memory
212
- # XXX should we consider a 4d array?
213
207
seg3d = np .ones ((3 , len (path )))
214
-
215
208
# Works both if zs is an array and a scalar
216
209
seg3d [2 , :] *= zs
217
210
@@ -230,12 +223,11 @@ def paths_to_3d_segments_with_codes(paths, zs=0, zdir='z'):
230
223
"""
231
224
232
225
zs = np .broadcast_to (zs , len (paths ))
233
- segments = []
234
- codes_list = []
235
- for path , pathz in zip (paths , zs ):
236
- segs , codes = path_to_3d_segment_with_codes (path , pathz , zdir )
237
- segments .append (segs )
238
- codes_list .append (codes )
226
+
227
+ path_generator = (path_to_3d_segment_with_codes (path , pathz , zdir )
228
+ for path , pathz in zip (paths , zs ))
229
+ segments , codes_list = zip (* path_generator )
230
+
239
231
return np .asarray (segments ), np .asarray (codes_list )
240
232
241
233
@@ -261,14 +253,11 @@ def set_segments(self, segments):
261
253
262
254
self ._segments3d_data = np .empty ((n_segments , 4 ))
263
255
self ._segments3d_data [:, :3 ] = np .vstack (segments )
264
- # Add a fourth dimension for quaternions
265
256
self ._segments3d_data [:, 3 ] = 1
266
257
267
258
# For coveniency, store a view of the array in the original shape
268
259
self ._segments3d = _array_split (self ._segments3d_data [:, :3 ],
269
260
np .cumsum (self ._seg_sizes ))
270
- else :
271
- self ._seg_sizes = np .array ([])
272
261
273
262
LineCollection .set_segments (self , [])
274
263
@@ -598,7 +587,7 @@ def get_vector(self, segments3d):
598
587
n_segments = np .sum (self ._seg_sizes )
599
588
# Put all segments in a big array
600
589
_vec = np .vstack (segments3d )
601
- # Add a fourth dimension for quaternions
590
+ # Add a fourth dimension
602
591
self ._vec = np .hstack ([_vec , np .ones ((n_segments , 1 ))]).T
603
592
604
593
def set_verts (self , verts , closed = True ):
0 commit comments