From ca9502eac8ca3bfacec66b74365d96481262dc1e Mon Sep 17 00:00:00 2001 From: Ryan May Date: Wed, 7 Mar 2018 13:27:35 -0700 Subject: [PATCH] BUG: Fix UnboundLocalError in contour labelling The code was trying to protect the access of xy1 and xy2 to valid cases, but unfortunately, for a list, l != -1 doesn't do element-by-element or return an error--it just always returns True. Therefore it wasn't actually guarding. --- lib/matplotlib/contour.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index d80b168ea90a..30fc59684df0 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -440,7 +440,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5): # Actually break contours if closed: # This will remove contour if shorter than label - if np.all(I != -1): + if all(i != -1 for i in I): nlc.append(np.row_stack([xy2, lc[I[1]:I[0]+1], xy1])) else: # These will remove pieces of contour if they have length zero