@@ -1090,23 +1090,37 @@ def set_verts(self, verts, closed=True):
10901090 Whether the polygon should be closed by adding a CLOSEPOLY
10911091 connection at the end.
10921092 """
1093+ self .stale = True
10931094 if isinstance (verts , np .ma .MaskedArray ):
10941095 verts = verts .astype (float ).filled (np .nan )
1095- # This is much faster than having Path do it one at a time.
1096- if closed :
1097- self ._paths = []
1098- for xy in verts :
1099- if len (xy ):
1100- if isinstance (xy , np .ma .MaskedArray ):
1101- xy = np .ma .concatenate ([xy , xy [:1 ]])
1102- else :
1103- xy = np .concatenate ([xy , xy [:1 ]])
1104- self ._paths .append (mpath .Path (xy , closed = True ))
1105- else :
1106- self ._paths .append (mpath .Path (xy ))
1107- else :
1096+
1097+ # No need to do anything fancy if the path isn't closed.
1098+ if not closed :
11081099 self ._paths = [mpath .Path (xy ) for xy in verts ]
1109- self .stale = True
1100+ return
1101+
1102+ # Fast path for arrays
1103+ if isinstance (verts , np .ndarray ):
1104+ verts_pad = np .concatenate ((verts , verts [:, :1 ]), axis = 1 )
1105+ # Creating the codes once is much faster than having Path do it
1106+ # separately each time by passing closed=True.
1107+ codes = np .empty (verts_pad .shape [1 ], dtype = mpath .Path .code_type )
1108+ codes [:] = mpath .Path .LINETO
1109+ codes [0 ] = mpath .Path .MOVETO
1110+ codes [- 1 ] = mpath .Path .CLOSEPOLY
1111+ self ._paths = [mpath .Path (xy , codes ) for xy in verts_pad ]
1112+ return
1113+
1114+ self ._paths = []
1115+ for xy in verts :
1116+ if len (xy ):
1117+ if isinstance (xy , np .ma .MaskedArray ):
1118+ xy = np .ma .concatenate ([xy , xy [:1 ]])
1119+ else :
1120+ xy = np .concatenate ([xy , xy [:1 ]])
1121+ self ._paths .append (mpath .Path (xy , closed = True ))
1122+ else :
1123+ self ._paths .append (mpath .Path (xy ))
11101124
11111125 set_paths = set_verts
11121126
0 commit comments