@@ -1090,23 +1090,36 @@ def set_verts(self, verts, closed=True):
1090
1090
Whether the polygon should be closed by adding a CLOSEPOLY
1091
1091
connection at the end.
1092
1092
"""
1093
+ self .stale = True
1094
+ # This is much faster than having Path do it one at a time.
1093
1095
if isinstance (verts , np .ma .MaskedArray ):
1094
1096
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 :
1097
+
1098
+ # No need to do anything fancy if the path isn't closed.
1099
+ if not closed :
1108
1100
self ._paths = [mpath .Path (xy ) for xy in verts ]
1109
- self .stale = True
1101
+ return
1102
+
1103
+ # Fast path for arrays
1104
+ if isinstance (verts , np .ndarray ):
1105
+ verts_pad = np .concatenate ((verts , verts [:, - 1 :]), axis = 1 )
1106
+ codes = np .empty (verts_pad .shape [1 ], dtype = mpath .Path .code_type )
1107
+ codes [:] = mpath .Path .LINETO
1108
+ codes [0 ] = mpath .Path .MOVETO
1109
+ codes [- 1 ] = mpath .Path .CLOSEPOLY
1110
+ self ._paths = [mpath .Path (xy , codes ) for xy in verts_pad ]
1111
+ return
1112
+
1113
+ self ._paths = []
1114
+ for xy in verts :
1115
+ if len (xy ):
1116
+ if isinstance (xy , np .ma .MaskedArray ):
1117
+ xy = np .ma .concatenate ([xy , xy [:1 ]])
1118
+ else :
1119
+ xy = np .concatenate ([xy , xy [:1 ]])
1120
+ self ._paths .append (mpath .Path (xy , closed = True ))
1121
+ else :
1122
+ self ._paths .append (mpath .Path (xy ))
1110
1123
1111
1124
set_paths = set_verts
1112
1125
0 commit comments