@@ -139,7 +139,6 @@ def _clip_mpl(self, gc, vertices, obj):
139139 intersection = line .intersection (cliprect )
140140
141141 if intersection .is_empty :
142- # if intersection is empty, return empty list of vertices
143142 vertices = [] # No intersection
144143 elif (
145144 "Multi" in intersection .geom_type
@@ -164,6 +163,7 @@ def _draw_mpl_lwpoly(self, gc, path, transform, obj):
164163 vertices = path .transformed (transform ).vertices
165164
166165 # Check if vertices hold NaN values
166+
167167 if np .isnan (vertices ).any ():
168168 nan_rows = np .isnan (vertices ).all (axis = 1 )
169169 split_indices = np .where (nan_rows )[0 ]
@@ -177,20 +177,55 @@ def _draw_mpl_lwpoly(self, gc, path, transform, obj):
177177 ]
178178
179179 for split_vertices in list_of_split_vertices :
180- self ._clip_and_add_mpl_lwpoly (gc , dxfattribs , split_vertices , obj )
180+ if split_vertices .size != 0 :
181+ # clip the polygon if clip rectangle present
182+
183+ if isinstance (split_vertices [0 ][0 ], float or np .float64 ):
184+ split_vertices = self ._clip_mpl (gc , split_vertices , obj = obj )
185+
186+ else :
187+ split_vertices = [
188+ self ._clip_mpl (gc , points , obj = obj )
189+ for points in split_vertices
190+ ]
191+
192+ # if vertices.
193+ if len (split_vertices ) == 0 :
194+ entity = None
195+
196+ else :
197+ if isinstance (split_vertices [0 ][0 ], float or np .float64 ):
198+ if split_vertices [0 ][0 ] != 0 :
199+ entity = self .modelspace .add_lwpolyline (
200+ points = split_vertices ,
201+ close = False ,
202+ dxfattribs = dxfattribs ,
203+ ) # set close to false because it broke some arrows
204+ else :
205+ entity = None
206+
207+ else :
208+ entity = [
209+ self .modelspace .add_lwpolyline (
210+ points = points , close = False , dxfattribs = dxfattribs
211+ )
212+ for points in split_vertices
213+ ] # set close to false because it broke some arrows
214+ return entity
181215 else :
182- self . _clip_and_add_mpl_lwpoly ( gc , dxfattribs , vertices , obj )
216+ # clip the polygon if clip rectangle present
183217
184- def _clip_and_add_mpl_lwpoly (self , gc , dxfattribs , vertices , obj ):
185- # clip the polygon if clip rectangle present
186- if len (vertices ) > 0 :
187218 if isinstance (vertices [0 ][0 ], float or np .float64 ):
188219 vertices = self ._clip_mpl (gc , vertices , obj = obj )
189220
190221 else :
191222 vertices = [self ._clip_mpl (gc , points , obj = obj ) for points in vertices ]
192223
193- if len (vertices ) > 0 :
224+ # if vertices.
225+ if len (vertices ) == 0 :
226+ entity = None
227+
228+ else :
194229 if isinstance (vertices [0 ][0 ], float or np .float64 ):
195230 if vertices [0 ][0 ] != 0 :
196231 entity = self .modelspace .add_lwpolyline (
@@ -206,12 +241,7 @@ def _clip_and_add_mpl_lwpoly(self, gc, dxfattribs, vertices, obj):
206241 )
207242 for points in vertices
208243 ] # set close to false because it broke some arrows
209- else :
210- entity = None
211- else :
212- entity = None
213-
214- return entity
244+ return entity
215245
216246 def _draw_mpl_line2d (self , gc , path , transform ):
217247 line = self ._draw_mpl_lwpoly (gc , path , transform , obj = "line2d" )
@@ -329,7 +359,7 @@ def draw_path_collection(
329359 paths ,
330360 all_transforms ,
331361 offsets ,
332- offsetTrans ,
362+ offset_trans ,
333363 facecolors ,
334364 edgecolors ,
335365 linewidths ,
@@ -343,10 +373,12 @@ def draw_path_collection(
343373 combined_transform = master_transform + all_transforms [i ]
344374 else :
345375 combined_transform = master_transform
346- facecolor = facecolors [i ] if i < len (facecolors ) else None
347- edgecolor = edgecolors [i ] if i < len (edgecolors ) else None
376+ if facecolors .size :
377+ rgbFace = facecolors [0 ] if facecolors is not None else None
378+ else :
379+ rgbFace = None
348380 # Draw each path as a filled patch
349- self ._draw_mpl_patch (gc , path , combined_transform , rgbFace = facecolor )
381+ self ._draw_mpl_patch (gc , path , combined_transform , rgbFace = rgbFace )
350382
351383 def draw_path (self , gc , path , transform , rgbFace = None ):
352384 # print('\nEntered ###DRAW_PATH###')
0 commit comments