99from cbook import is_string_like , enumerate , strip_math , Stack
1010from colors import colorConverter
1111from numerix import array , sqrt , pi , log , asarray , ones , zeros , Float , Float32
12- from numerix import arange , compress , take
12+ from numerix import arange , compress , take , isnan , any
1313from patches import Rectangle
1414from transforms import lbwh_to_bbox , identity_transform
1515import widgets
@@ -92,7 +92,7 @@ def draw_line_collection(self, segments, transform, clipbox,
9292 matplotlib.collections for more details.
9393
9494 segments is a sequence of ( line0, line1, line2), where linen =
95- (x0, y0), (x1, y1), ... (xm, ym) . Each line can be a
95+ is an Mx2 array with columns x, y . Each line can be a
9696 different length
9797
9898 transform is used to Transform the lines
@@ -110,8 +110,9 @@ def draw_line_collection(self, segments, transform, clipbox,
110110 antialiseds is a tuple of ones or zeros indicating whether the
111111 segment should be aa or not
112112
113- offsets, if not None, is a list of x,y offsets to translate the lines
114- by after transform is used to transform the offset coords
113+ offsets, if not None, is an Nx2 array of x,y offsets to
114+ translate the lines by after transform is used to transform
115+ the offset coords
115116
116117 This function could be overridden in the backend to possibly implement
117118 faster drawing, but it is already much faster than using draw_lines()
@@ -133,7 +134,8 @@ def draw_line_collection(self, segments, transform, clipbox,
133134 usingOffsets = offsets is not None
134135 Noffsets = 0
135136 if usingOffsets :
136- Noffsets = len (offsets )
137+ Noffsets = offsets .shape [0 ]
138+ offsets = transOffset .numerix_xy (offsets )
137139
138140 for i in xrange (max (Noffsets , Nsegments )):
139141 color = colors [i % Nc ]
@@ -146,16 +148,12 @@ def draw_line_collection(self, segments, transform, clipbox,
146148 gc .set_antialiased ( antialiaseds [i % Naa ] )
147149 seg = segments [i % Nsegments ]
148150 if not len (seg ): continue
149- x , y = zip (* seg )
150-
151- x , y = transform .numerix_x_y (array (x ), array (y ))
151+ xy = transform .numerix_xy (seg )
152152 if usingOffsets :
153- xo , yo = transOffset .xy_tup (offsets [i % Noffsets ])
154- x += xo
155- y += yo
153+ xy = xy + offsets [i % Noffsets ]
156154
157- if newstyle : self .draw_lines (gc , x , y , identity )
158- else : self .draw_lines (gc , x , y )
155+ if newstyle : self .draw_lines (gc , xy [:, 0 ], xy [:, 1 ] , identity )
156+ else : self .draw_lines (gc , xy [:, 0 ], xy [:, 1 ] )
159157
160158 def draw_line (self , gc , x1 , y1 , x2 , y2 ):
161159 """
@@ -241,7 +239,9 @@ def draw_poly_collection(
241239 gc .set_clip_rectangle (clipbox .get_bounds ())
242240
243241 for i in xrange (N ):
244-
242+ polyverts = verts [i % Nverts ]
243+ if any (isnan (polyverts )):
244+ continue
245245 linewidth = linewidths [i % Nlw ]
246246 rf ,gf ,bf ,af = facecolors [i % Nface ]
247247 re ,ge ,be ,ae = edgecolors [i % Nedge ]
@@ -265,7 +265,7 @@ def draw_poly_collection(
265265
266266 gc .set_antialiased ( antialiaseds [i % Naa ] ) # Used for fill only?
267267 gc .set_alpha ( alpha )
268- tverts = transform .seq_xy_tups (verts [ i % Nverts ] )
268+ tverts = transform .seq_xy_tups (polyverts )
269269 if usingOffsets :
270270 xo ,yo = transOffset .xy_tup (offsets [i % Noffsets ])
271271 tverts = [(x + xo ,y + yo ) for x ,y in tverts ]
0 commit comments