From 23664c53c207b489874b2aa330208ab2ae8e94cc Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 1 Dec 2017 11:20:46 -0800 Subject: [PATCH 1/2] Deprecate unused ContourLabeler.get_real_label_width. --- doc/api/api_changes/2017-12-01-AL.rst | 4 ++++ lib/matplotlib/contour.py | 1 + 2 files changed, 5 insertions(+) create mode 100644 doc/api/api_changes/2017-12-01-AL.rst diff --git a/doc/api/api_changes/2017-12-01-AL.rst b/doc/api/api_changes/2017-12-01-AL.rst new file mode 100644 index 000000000000..ff86ce58a54f --- /dev/null +++ b/doc/api/api_changes/2017-12-01-AL.rst @@ -0,0 +1,4 @@ +Deprecation of unused methods +````````````````````````````` + +The unused ``ContourLabeler.get_real_label_width`` method is deprecated. diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index ecbde9ae91b5..a4e08951a3a8 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -289,6 +289,7 @@ def get_label_width(self, lev, fmt, fsize): return lw + @cbook.deprecated("2.2") def get_real_label_width(self, lev, fmt, fsize): """ This computes actual onscreen label width. From df4e62300edda78b05782aee6eb036f3d7f32457 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 1 Dec 2017 11:50:30 -0800 Subject: [PATCH 2/2] Some more cleanups. --- lib/matplotlib/contour.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index a4e08951a3a8..afba7812a224 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -337,8 +337,7 @@ def get_text(self, lev, fmt): def locate_label(self, linecontour, labelwidth): """ - Find a good place to plot a label (relatively flat - part of the contour). + Find good place to draw a label (relatively flat part of the contour). """ # Number of contour points @@ -355,16 +354,15 @@ def locate_label(self, linecontour, labelwidth): XX = np.resize(linecontour[:, 0], (xsize, ysize)) YY = np.resize(linecontour[:, 1], (xsize, ysize)) # I might have fouled up the following: - yfirst = YY[:, 0].reshape(xsize, 1) - ylast = YY[:, -1].reshape(xsize, 1) - xfirst = XX[:, 0].reshape(xsize, 1) - xlast = XX[:, -1].reshape(xsize, 1) + yfirst = YY[:, :1] + ylast = YY[:, -1:] + xfirst = XX[:, :1] + xlast = XX[:, -1:] s = (yfirst - YY) * (xlast - xfirst) - (xfirst - XX) * (ylast - yfirst) - L = np.sqrt((xlast - xfirst) ** 2 + (ylast - yfirst) ** 2).ravel() + L = np.hypot(xlast - xfirst, ylast - yfirst) # Ignore warning that divide by zero throws, as this is a valid option with np.errstate(divide='ignore', invalid='ignore'): - dist = np.add.reduce([(abs(s)[i] / L[i]) for i in range(xsize)], - -1) + dist = np.sum(np.abs(s) / L, axis=-1) x, y, ind = self.get_label_coords(dist, XX, YY, ysize, labelwidth) # There must be a more efficient way...