Skip to content

Deprecate unused ContourLabeler.get_real_label_width. #9904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/api_changes/2017-12-01-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deprecation of unused methods
`````````````````````````````

The unused ``ContourLabeler.get_real_label_width`` method is deprecated.
17 changes: 8 additions & 9 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -336,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
Expand All @@ -354,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...
Expand Down