@@ -131,9 +131,6 @@ def _clip_mpl(self, gc, vertices, obj):
131131 [bbox .x0 , bbox .y1 ],
132132 ]
133133
134- # Remove any NaN values from the vertices
135- vertices = vertices [~ np .isnan (vertices ).any (axis = 1 )]
136-
137134 if obj == "patch" :
138135 vertices = ClippingRect2d (cliprect [0 ], cliprect [2 ]).clip_polyline (
139136 vertices
@@ -168,6 +165,25 @@ def _draw_mpl_lwpoly(self, gc, path, transform, obj):
168165 dxfattribs = self ._get_polyline_attribs (gc )
169166 vertices = path .transformed (transform ).vertices
170167
168+ # Check if vertices hold NaN values
169+ if np .isnan (vertices ).any ():
170+ nan_rows = np .isnan (vertices ).all (axis = 1 )
171+ split_indices = np .where (nan_rows )[0 ]
172+
173+ # Split the array at NaN indices
174+ list_of_split_vertices = np .split (vertices , split_indices )
175+
176+ # Remove NaN values from sub-arrays
177+ list_of_split_vertices = [
178+ arr [~ np .isnan (arr ).any (axis = 1 )] for arr in list_of_split_vertices
179+ ]
180+
181+ for split_vertices in list_of_split_vertices :
182+ self ._clip_and_add_mpl_lwpoly (gc , dxfattribs , split_vertices , obj )
183+ else :
184+ self ._clip_and_add_mpl_lwpoly (gc , dxfattribs , vertices , obj )
185+
186+ def _clip_and_add_mpl_lwpoly (self , gc , dxfattribs , vertices , obj ):
171187 # clip the polygon if clip rectangle present
172188 if len (vertices ) > 0 :
173189 if isinstance (vertices [0 ][0 ], float or np .float64 ):
0 commit comments