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

Skip to content

Commit 79898c3

Browse files
committed
Take review comments into account
1 parent 55b83c6 commit 79898c3

File tree

4 files changed

+11
-100
lines changed

4 files changed

+11
-100
lines changed

doc/api/next_api_changes/removals/24984-OG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ parameter are removed. Instead, use ``set_params(base=..., subs=...)``.
4141
~~~~~~~~~~~~~~~~~~~~~~~~~~~
4242

4343
The canvas now takes care of the renderer and whether to cache it or not,
44-
so the ````Axes.get_renderer_cache`` method is removed. The
44+
so the ``Axes.get_renderer_cache`` method is removed. The
4545
alternative is to call ``axes.figure.canvas.get_renderer()``.
4646

4747
Unused methods in ``Axis``, ``Tick``, ``XAxis``, and ``YAxis``

lib/matplotlib/mlab.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -210,39 +210,6 @@ def detrend_linear(y):
210210
return y - (b*x + a)
211211

212212

213-
def _stride_windows(x, n, noverlap=0):
214-
"""
215-
Get all windows of *x* with length *n* as a single array,
216-
using strides to avoid data duplication.
217-
218-
.. warning::
219-
220-
It is not safe to write to the output array. Multiple
221-
elements may point to the same piece of memory,
222-
so modifying one value may change others.
223-
224-
Parameters
225-
----------
226-
x : 1D array or sequence
227-
Array or sequence containing the data.
228-
n : int
229-
The number of data points in each window.
230-
noverlap : int, default: 0 (no overlap)
231-
The overlap between adjacent windows.
232-
233-
References
234-
----------
235-
`stackoverflow: Rolling window for 1D arrays in Numpy?
236-
<https://stackoverflow.com/a/6811241>`_
237-
`stackoverflow: Using strides for an efficient moving average filter
238-
<https://stackoverflow.com/a/4947453>`_
239-
"""
240-
if noverlap >= n:
241-
raise ValueError('noverlap must be less than n')
242-
return np.lib.stride_tricks.sliding_window_view(
243-
x, n, axis=0)[::n - noverlap].T
244-
245-
246213
def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
247214
window=None, noverlap=None, pad_to=None,
248215
sides=None, scale_by_freq=None, mode=None):
@@ -272,6 +239,9 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
272239
if NFFT is None:
273240
NFFT = 256
274241

242+
if noverlap >= NFFT:
243+
raise ValueError('noverlap must be less than NFFT')
244+
275245
if mode is None or mode == 'default':
276246
mode = 'psd'
277247
_api.check_in_list(
@@ -334,15 +304,17 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
334304
raise ValueError(
335305
"The window length must match the data's first dimension")
336306

337-
result = _stride_windows(x, NFFT, noverlap)
307+
result = np.lib.stride_tricks.sliding_window_view(
308+
x, NFFT, axis=0)[::NFFT - noverlap].T
338309
result = detrend(result, detrend_func, axis=0)
339310
result = result * window.reshape((-1, 1))
340311
result = np.fft.fft(result, n=pad_to, axis=0)[:numFreqs, :]
341312
freqs = np.fft.fftfreq(pad_to, 1/Fs)[:numFreqs]
342313

343314
if not same_data:
344315
# if same_data is False, mode must be 'psd'
345-
resultY = _stride_windows(y, NFFT, noverlap)
316+
resultY = np.lib.stride_tricks.sliding_window_view(
317+
y, NFFT, axis=0)[::NFFT - noverlap].T
346318
resultY = detrend(resultY, detrend_func, axis=0)
347319
resultY = resultY * window.reshape((-1, 1))
348320
resultY = np.fft.fft(resultY, n=pad_to, axis=0)[:numFreqs, :]

lib/matplotlib/tests/test_mlab.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,6 @@
66
from matplotlib import mlab
77

88

9-
class TestStride:
10-
def get_base(self, x):
11-
y = x
12-
while y.base is not None:
13-
y = y.base
14-
return y
15-
16-
def calc_window_target(self, x, NFFT, noverlap=0):
17-
"""
18-
This is an adaptation of the original window extraction algorithm.
19-
This is here to test to make sure the new implementation has the same
20-
result.
21-
"""
22-
step = NFFT - noverlap
23-
ind = np.arange(0, len(x) - NFFT + 1, step)
24-
n = len(ind)
25-
result = np.zeros((NFFT, n))
26-
27-
# do the ffts of the slices
28-
for i in range(n):
29-
result[:, i] = x[ind[i]:ind[i]+NFFT]
30-
return result
31-
32-
@pytest.mark.parametrize('n, noverlap',
33-
[(2, 2), (2, 3)],
34-
ids=['noverlap greater than n',
35-
'noverlap equal to n'])
36-
def test_stride_windows_invalid_params(self, n, noverlap):
37-
x = np.arange(10)
38-
with pytest.raises(ValueError):
39-
mlab._stride_windows(x, n, noverlap)
40-
41-
@pytest.mark.parametrize('n, noverlap',
42-
[(1, 0), (5, 0), (15, 2), (13, -3)],
43-
ids=['n1-noverlap0', 'n5-noverlap0',
44-
'n15-noverlap2', 'n13-noverlapn3'])
45-
def test_stride_windows(self, n, noverlap):
46-
x = np.arange(100)
47-
y = mlab._stride_windows(x, n, noverlap=noverlap)
48-
49-
expected_shape = [0, 0]
50-
expected_shape[0] = n
51-
expected_shape[1] = 100 // (n - noverlap)
52-
yt = self.calc_window_target(x, n, noverlap=noverlap)
53-
54-
assert yt.shape == y.shape
55-
assert_array_equal(yt, y)
56-
assert tuple(expected_shape) == y.shape
57-
assert self.get_base(y) is x
58-
59-
def test_stride_windows_n32_noverlap0_unflatten(self):
60-
n = 32
61-
x = np.arange(n)[np.newaxis]
62-
x1 = np.tile(x, (21, 1))
63-
x2 = x1.flatten()
64-
y = mlab._stride_windows(x2, n)
65-
66-
x1 = x1.T
67-
assert y.shape == x1.shape
68-
assert_array_equal(y, x1)
69-
70-
719
def test_window():
7210
np.random.seed(0)
7311
n = 1000

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ def draw_pane(self, renderer):
319319
plane = self._PLANES[2 * index]
320320
else:
321321
plane = self._PLANES[2 * index + 1]
322-
xys = [tc[p] for p in plane]
323-
self._set_pane_pos(xys)
322+
xys = np.asarray([tc[p] for p in plane])
323+
xys = xys[:, :2]
324+
self.pane.xy = xys
324325
self.pane.draw(renderer)
325326

326327
renderer.close_group('pane3d')

0 commit comments

Comments
 (0)