diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 4ab377f4b660..06d5c645967f 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2139,11 +2139,12 @@ def clip_cmd(self, cliprect, clippath): """Set clip rectangle. Calls self.pop() and self.push().""" cmds = [] # Pop graphics state until we hit the right one or the stack is empty - while (self._cliprect, self._clippath) != (cliprect, clippath) \ - and self.parent is not None: + while ((self._cliprect, self._clippath) != (cliprect, clippath) + and self.parent is not None): cmds.extend(self.pop()) # Unless we hit the right one, set the clip polygon - if (self._cliprect, self._clippath) != (cliprect, clippath): + if ((self._cliprect, self._clippath) != (cliprect, clippath) or + self.parent is None): cmds.extend(self.push()) if self._cliprect != cliprect: cmds.extend([cliprect, Op.rectangle, Op.clip, Op.endpath])