Skip to content

Commit 6750726

Browse files
3D fill_between auto mode maps to polygon when all points lie on a x, y, or z plane
1 parent 659ec35 commit 6750726

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

galleries/examples/mplot3d/fillunder3d.py

-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@
2424

2525
for i, l in enumerate(lambdas):
2626
# Note fill_between can take coordinates as length N vectors, or scalars
27-
# mode='polygon' is set for faster and cleaner rendering for this shape on
28-
# a single plane.
2927
ax.fill_between(x, l, l**x * np.exp(-l) / gamma(x + 1),
3028
x, l, 0,
31-
mode='polygon',
3229
facecolors=facecolors[i], alpha=.7)
3330

3431
ax.set(xlim=(0, 10), ylim=(1, 9), zlim=(0, 0.35),

lib/mpl_toolkits/mplot3d/axes3d.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -1985,15 +1985,16 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
19851985
the *True* position remain unfilled due to the adjacent *False*
19861986
values.
19871987
1988-
mode : {'auto', 'quad', 'polygon'}, default: 'auto'
1989-
The fill mode, where 'auto' maps to 'quad'.
1990-
If 'quad', then a separate quadrilateral polygon is created for
1991-
each pair of subsequent points in the 1st and 2nd lines. This is
1992-
more flexible, but may be slower and result in rendering artifacts.
1993-
If 'polygon', then the 1st and 2nd lines are connected to form a single
1994-
polygon, which may be faster and render more cleanly for simple
1995-
shapes (eg, for filling between two lines that lie on a single
1996-
plane).
1988+
mode : {'quad', 'polygon', 'auto'}, default: 'auto'
1989+
The fill mode. One of:
1990+
- 'quad': A separate quadrilateral polygon is created for each
1991+
pair of subsequent points in the two lines.
1992+
- 'polygon': The two lines are connected to form a single polygon.
1993+
This is faster and can render more cleanly for simple shapes
1994+
(e.g. for filling between two lines that lie within a plane).
1995+
- '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+
'polygon' is used. Otherwise, 'quad' is used.
19971998
19981999
**kwargs
19992000
All other keyword arguments are passed on to `.Poly3DCollection`.
@@ -2005,11 +2006,16 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
20052006
20062007
"""
20072008
_api.check_in_list(['auto', 'quad', 'polygon'], mode=mode)
2008-
if mode == 'auto':
2009-
mode = 'quad'
20102009

20112010
had_data = self.has_data()
20122011
x1, y1, z1, x2, y2, z2 = cbook._broadcast_with_masks(x1, y1, z1, x2, y2, z2)
2012+
if mode == 'auto':
2013+
if ((np.all(x1 == x1[0]) and np.all(x2 == x1[0]))
2014+
or (np.all(y1 == y1[0]) and np.all(y2 == y1[0]))
2015+
or (np.all(z1 == z1[0]) and np.all(z2 == z1[0]))):
2016+
mode = 'polygon'
2017+
else:
2018+
mode = 'quad'
20132019

20142020
if where is None:
20152021
where = True

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,10 @@ def test_fill_between_quad():
610610

611611
where = (theta < np.pi/2) | (theta > 3*np.pi/2)
612612

613+
# Since none of x1 == x2, y1 == y2, or z1 == z2 is True, the fill_between
614+
# mode will map to 'quad'
613615
ax.fill_between(x1, y1, z1, x2, y2, z2,
614-
where=where, alpha=0.5, edgecolor='k')
616+
where=where, mode='auto', alpha=0.5, edgecolor='k')
615617

616618

617619
@mpl3d_image_comparison(['fill_between_polygon.png'], style='mpl20')
@@ -628,8 +630,9 @@ def test_fill_between_polygon():
628630

629631
where = (theta < np.pi/2) | (theta > 3*np.pi/2)
630632

633+
# Since x1 == x2 and y1 == y2, the fill_between mode will be 'polygon'
631634
ax.fill_between(x1, y1, z1, x2, y2, z2,
632-
where=where, mode='polygon', edgecolor='k')
635+
where=where, mode='auto', edgecolor='k')
633636

634637

635638
@mpl3d_image_comparison(['surface3d.png'], style='mpl20')

0 commit comments

Comments
 (0)