Thanks to visit codestin.com
Credit goes to github.com

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
Changes from 1 commit
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
Prev Previous commit
Some more cleanups.
  • Loading branch information
anntzer committed Dec 1, 2017
commit df4e62300edda78b05782aee6eb036f3d7f32457
16 changes: 7 additions & 9 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...
Expand Down