Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df4e623

Browse filesBrowse files
committed
Some more cleanups.
1 parent 23664c5 commit df4e623
Copy full SHA for df4e623

File tree

Expand file treeCollapse file tree

1 file changed

+7
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-9
lines changed

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ def get_text(self, lev, fmt):
337337

338338
def locate_label(self, linecontour, labelwidth):
339339
"""
340-
Find a good place to plot a label (relatively flat
341-
part of the contour).
340+
Find good place to draw a label (relatively flat part of the contour).
342341
"""
343342

344343
# Number of contour points
@@ -355,16 +354,15 @@ def locate_label(self, linecontour, labelwidth):
355354
XX = np.resize(linecontour[:, 0], (xsize, ysize))
356355
YY = np.resize(linecontour[:, 1], (xsize, ysize))
357356
# I might have fouled up the following:
358-
yfirst = YY[:, 0].reshape(xsize, 1)
359-
ylast = YY[:, -1].reshape(xsize, 1)
360-
xfirst = XX[:, 0].reshape(xsize, 1)
361-
xlast = XX[:, -1].reshape(xsize, 1)
357+
yfirst = YY[:, :1]
358+
ylast = YY[:, -1:]
359+
xfirst = XX[:, :1]
360+
xlast = XX[:, -1:]
362361
s = (yfirst - YY) * (xlast - xfirst) - (xfirst - XX) * (ylast - yfirst)
363-
L = np.sqrt((xlast - xfirst) ** 2 + (ylast - yfirst) ** 2).ravel()
362+
L = np.hypot(xlast - xfirst, ylast - yfirst)
364363
# Ignore warning that divide by zero throws, as this is a valid option
365364
with np.errstate(divide='ignore', invalid='ignore'):
366-
dist = np.add.reduce([(abs(s)[i] / L[i]) for i in range(xsize)],
367-
-1)
365+
dist = np.sum(np.abs(s) / L, axis=-1)
368366
x, y, ind = self.get_label_coords(dist, XX, YY, ysize, labelwidth)
369367

370368
# There must be a more efficient way...

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.