Skip to content

Commit e76a19a

Browse files
committed
adding more checks on when simplification occurs
1 parent 00546dd commit e76a19a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/matplotlib/lines.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,21 @@ def draw(self, renderer):
790790
cap = self._dashcapstyle
791791
join = self._dashjoinstyle
792792
else:
793-
print(tpath.vertices.size)
794-
tpath = affine.inverted().transform_path(affine.transform_path(tpath).cleaned(simplify=True))
795-
print(tpath.vertices.size)
793+
if tpath.should_simplify and affine.has_inverse:
794+
# the path simplification code expects the path
795+
# to be in pixel space, not data space, but the
796+
# renderer downstream expects the path to be
797+
# in data space. The transformation `affine`
798+
# will put the path into pixel space, and
799+
# affine.inverted() will transform it back to
800+
# data space. So, transform using affine, simplify
801+
# the path, and transform using the affine inverted.
802+
tpath = affine.inverted().transform_path(
803+
affine.transform_path(tpath).cleaned(simplify=True)
804+
)
796805
cap = self._solidcapstyle
797806
join = self._solidjoinstyle
807+
798808
gc.set_joinstyle(join)
799809
gc.set_capstyle(cap)
800810
gc.set_snap(self.get_snap())

lib/matplotlib/path.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
206206
return pth
207207

208208
def _update_values(self):
209+
self._simplify_threshold = rcParams['path.simplify_threshold']
209210
self._should_simplify = (
210211
rcParams['path.simplify'] and
211-
(len(self._vertices) >= 128 and
212-
(self._codes is None or np.all(self._codes <= Path.LINETO)))
212+
len(self._vertices) >= 128 and
213+
(self._codes is None or np.all(self._codes <= Path.LINETO)) and
214+
self._simplify_threshold > 0
213215
)
214-
self._simplify_threshold = rcParams['path.simplify_threshold']
215216
self._has_nonfinite = not np.isfinite(self._vertices).all()
216217

217218
@property

0 commit comments

Comments
 (0)