Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da73386

Browse files
committed
Ignore non-draw codes when calculating path extent
1 parent 7a0d656 commit da73386

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/matplotlib/path.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class Path:
9595
CURVE4: 3,
9696
CLOSEPOLY: 1}
9797

98+
#: A list of the codes that do not draw anything
99+
NON_DRAW_CODES = [MOVETO, CLOSEPOLY, STOP]
100+
98101
def __init__(self, vertices, codes=None, _interpolation_steps=1,
99102
closed=False, readonly=False):
100103
"""
@@ -620,11 +623,17 @@ def get_extents(self, transform=None, **kwargs):
620623
self = transform.transform_path(self)
621624
if self.codes is None:
622625
xys = self.vertices
626+
# Short cut the case with only straight lines
623627
elif len(np.intersect1d(self.codes, [Path.CURVE3, Path.CURVE4])) == 0:
624-
xys = self.vertices[self.codes != Path.CLOSEPOLY]
628+
draw_idxs = np.nonzero(self.codes == Path.LINETO)[0]
629+
# Include the start and end point of each line
630+
draw_idxs = np.union1d(draw_idxs, draw_idxs - 1)
631+
xys = self.vertices[draw_idxs]
625632
else:
626633
xys = []
627634
for curve, code in self.iter_bezier(**kwargs):
635+
if code in Path.NON_DRAW_CODES:
636+
continue
628637
# places where the derivative is zero can be extrema
629638
_, dzeros = curve.axis_aligned_extrema()
630639
# as can the ends of the curve

0 commit comments

Comments
 (0)