Skip to content

Commit bf8cde7

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 bf8cde7

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

galleries/examples/mplot3d/fillunder3d.py

Lines changed: 0 additions & 3 deletions
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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,14 +1986,17 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
19861986
values.
19871987
19881988
mode : {'auto', 'quad', 'polygon'}, default: 'auto'
1989-
The fill mode, where 'auto' maps to 'quad'.
1989+
The fill mode.
1990+
If 'auto' and all the coordinates for the x, y, or z input pairs
1991+
are the same, then the points lie on a plane and 'polygon' is used.
1992+
Otherwise, 'auto' defaults to 'quad'.
19901993
If 'quad', then a separate quadrilateral polygon is created for
19911994
each pair of subsequent points in the 1st and 2nd lines. This is
19921995
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).
1996+
If 'polygon', then the 1st and 2nd lines are connected to form a
1997+
single polygon, which may be faster and render more cleanly for
1998+
simple shapes (eg, for filling between two lines that lie on a
1999+
single plane).
19972000
19982001
**kwargs
19992002
All other keyword arguments are passed on to `.Poly3DCollection`.
@@ -2005,11 +2008,14 @@ def fill_between(self, x1, y1, z1, x2, y2, z2, *,
20052008
20062009
"""
20072010
_api.check_in_list(['auto', 'quad', 'polygon'], mode=mode)
2008-
if mode == 'auto':
2009-
mode = 'quad'
20102011

20112012
had_data = self.has_data()
20122013
x1, y1, z1, x2, y2, z2 = cbook._broadcast_with_masks(x1, y1, z1, x2, y2, z2)
2014+
if mode == 'auto':
2015+
if np.all(x1 == x2) or np.all(y1 == y2) or np.all(z1 == z2):
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

Lines changed: 5 additions & 2 deletions
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)