Skip to content

Commit b88c8a1

Browse files
Code review comments
1 parent 6750726 commit b88c8a1

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -1987,13 +1987,14 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
19871987
19881988
mode : {'quad', 'polygon', 'auto'}, default: 'auto'
19891989
The fill mode. One of:
1990+
19901991
- 'quad': A separate quadrilateral polygon is created for each
19911992
pair of subsequent points in the two lines.
19921993
- 'polygon': The two lines are connected to form a single polygon.
19931994
This is faster and can render more cleanly for simple shapes
19941995
(e.g. for filling between two lines that lie within a plane).
19951996
- '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),
19971998
'polygon' is used. Otherwise, 'quad' is used.
19981999
19992000
**kwargs
@@ -2028,29 +2029,29 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
20282029

20292030
polys = []
20302031
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):
20392040
continue
20402041

20412042
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]
20482051
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)
20542055
polys.append(poly)
20552056

20562057
polyc = art3d.Poly3DCollection(polys, **kwargs)

0 commit comments

Comments
 (0)