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

Skip to content

Commit ac8f801

Browse files
committed
MAINT: Extract helper function to cbook
1 parent 3b4003f commit ac8f801

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,3 +2067,42 @@ def method(self, *args, **kwargs):
20672067
raise NotImplementedError("Parent class already defines aliases")
20682068
cls._alias_map = alias_d
20692069
return cls
2070+
2071+
2072+
def _array_perimeter(arr):
2073+
"""
2074+
Get the elements on the perimeter of ``arr``,
2075+
2076+
Parameters
2077+
----------
2078+
arr : ndarray, shape (M, N)
2079+
The input array
2080+
2081+
Returns
2082+
-------
2083+
perimeter : ndarray, shape (2*(M - 1) + 2*(N - 1),)
2084+
The elements on the perimeter of the array::
2085+
2086+
[arr[0,0] ... arr[0,-1] ... arr[-1, -1] ... arr[-1,0] ...]
2087+
2088+
Examples
2089+
--------
2090+
>>> i, j = np.ogrid[:3,:4]
2091+
>>> a = i*10 + j
2092+
>>> a
2093+
array([[ 0, 1, 2, 3],
2094+
[10, 11, 12, 13],
2095+
[20, 21, 22, 23]])
2096+
>>> _array_perimeter(arr)
2097+
array([ 0, 1, 2, 3, 13, 23, 22, 21, 20, 10])
2098+
"""
2099+
# note we use Python's half-open ranges to avoid repeating
2100+
# the corners
2101+
forward = np.s_[0:-1] # [0 ... -1)
2102+
backward = np.s_[-1:0:-1] # [-1 ... 0)
2103+
return np.concatenate((
2104+
arr[0, forward],
2105+
arr[forward, -1],
2106+
arr[-1, backward],
2107+
arr[backward, 0],
2108+
))

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,25 +1684,6 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
16841684
if shade and cmap is not None and fcolors is not None:
16851685
fcolors = self._shade_colors_lightsource(Z, cmap, lightsource)
16861686

1687-
def boundary_edge(arr):
1688-
"""
1689-
Get the boundary elements of the rectangle ``arr``,
1690-
1691-
[arr[0,0] ... arr[0,-1] ... arr[-1, -1] ... arr[-1,0] ...]
1692-
1693-
If arr.shape is (M, N), the result is of length 2(N+M-2)
1694-
"""
1695-
# note we use Python's half-open ranges to avoid repeating
1696-
# the corners
1697-
forward = np.s_[0:-1] # [0 ... -1)
1698-
backward = np.s_[-1:0:-1] # [-1 ... 0)
1699-
return np.concatenate((
1700-
arr[0, forward],
1701-
arr[forward, -1],
1702-
arr[-1, backward],
1703-
arr[backward, 0],
1704-
))
1705-
17061687
# evenly spaced, and including both endpoints
17071688
row_inds = list(range(0, rows-1, rstride)) + [rows-1]
17081689
col_inds = list(range(0, cols-1, cstride)) + [cols-1]
@@ -1713,7 +1694,7 @@ def boundary_edge(arr):
17131694
for cs, cs_next in zip(col_inds[:-1], col_inds[1:]):
17141695
ps = [
17151696
# +1 ensures we share edges between polygons
1716-
boundary_edge(a[rs:rs_next+1, cs:cs_next+1])
1697+
cbook._array_perimeter(a[rs:rs_next+1, cs:cs_next+1])
17171698
for a in (X, Y, Z)
17181699
]
17191700
# ps = np.stack(ps, axis=-1)

0 commit comments

Comments
 (0)