@@ -1987,13 +1987,14 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
1987
1987
1988
1988
mode : {'quad', 'polygon', 'auto'}, default: 'auto'
1989
1989
The fill mode. One of:
1990
+
1990
1991
- 'quad': A separate quadrilateral polygon is created for each
1991
1992
pair of subsequent points in the two lines.
1992
1993
- 'polygon': The two lines are connected to form a single polygon.
1993
1994
This is faster and can render more cleanly for simple shapes
1994
1995
(e.g. for filling between two lines that lie within a plane).
1995
1996
- 'auto': If the lines are in a plane parallel to a coordinate axis
1996
- (one of *x*, *y*, *z* for both lines are constant and equal),
1997
+ (one of *x*, *y*, *z* are constant and equal for both lines ),
1997
1998
'polygon' is used. Otherwise, 'quad' is used.
1998
1999
1999
2000
**kwargs
@@ -2028,29 +2029,29 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
2028
2029
2029
2030
polys = []
2030
2031
for idx0 , idx1 in cbook .contiguous_regions (where ):
2031
- x1slice = x1 [idx0 :idx1 ]
2032
- y1slice = y1 [idx0 :idx1 ]
2033
- z1slice = z1 [idx0 :idx1 ]
2034
- x2slice = x2 [idx0 :idx1 ]
2035
- y2slice = y2 [idx0 :idx1 ]
2036
- z2slice = z2 [idx0 :idx1 ]
2037
-
2038
- if not len (x1slice ):
2032
+ x1i = x1 [idx0 :idx1 ]
2033
+ y1i = y1 [idx0 :idx1 ]
2034
+ z1i = z1 [idx0 :idx1 ]
2035
+ x2i = x2 [idx0 :idx1 ]
2036
+ y2i = y2 [idx0 :idx1 ]
2037
+ z2i = z2 [idx0 :idx1 ]
2038
+
2039
+ if not len (x1i ):
2039
2040
continue
2040
2041
2041
2042
if mode == 'quad' :
2042
- for i in range (len (x1slice ) - 1 ):
2043
- poly = [(x1slice [i ], y1slice [i ], z1slice [i ]),
2044
- (x1slice [i + 1 ], y1slice [i + 1 ], z1slice [i + 1 ]),
2045
- (x2slice [i + 1 ], y2slice [i + 1 ], z2slice [i + 1 ]),
2046
- (x2slice [i ], y2slice [i ], z2slice [i ])]
2047
- polys .append (poly )
2043
+ # Preallocate the array for the region's vertices, and fill it in
2044
+ n_polys_i = len (x1i ) - 1
2045
+ polys_i = np .empty ((n_polys_i , 4 , 3 ))
2046
+ polys_i [:, 0 , :] = np .column_stack ((x1i [:- 1 ], y1i [:- 1 ], z1i [:- 1 ]))
2047
+ polys_i [:, 1 , :] = np .column_stack ((x1i [1 :], y1i [1 :], z1i [1 :]))
2048
+ polys_i [:, 2 , :] = np .column_stack ((x2i [1 :], y2i [1 :], z2i [1 :]))
2049
+ polys_i [:, 3 , :] = np .column_stack ((x2i [:- 1 ], y2i [:- 1 ], z2i [:- 1 ]))
2050
+ polys = polys + [* polys_i ]
2048
2051
elif mode == 'polygon' :
2049
- poly = []
2050
- for i in range (len (x1slice )):
2051
- poly .append ((x1slice [i ], y1slice [i ], z1slice [i ]))
2052
- for i in range (len (x2slice ) - 1 , - 1 , - 1 ):
2053
- poly .append ((x2slice [i ], y2slice [i ], z2slice [i ]))
2052
+ line1 = np .column_stack ((x1i , y1i , z1i ))
2053
+ line2 = np .column_stack ((x2i [::- 1 ], y2i [::- 1 ], z2i [::- 1 ]))
2054
+ poly = np .concatenate ((line1 , line2 ), axis = 0 )
2054
2055
polys .append (poly )
2055
2056
2056
2057
polyc = art3d .Poly3DCollection (polys , ** kwargs )
0 commit comments