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

Skip to content

Commit 78aff43

Browse files
committed
MNT: deprecate mlab
.... except for GaussianKDE, which is needed for violinplots
1 parent 1f7151e commit 78aff43

27 files changed

+12
-1329
lines changed

lib/matplotlib/mlab.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
2-
Numerical Python functions written for compatibility with MATLAB
3-
commands with the same names. Most numerical Python functions can be found in
4-
the `NumPy`_ and `SciPy`_ libraries. What remains here is code for performing
5-
spectral computations and kernel density estimations.
2+
This module is deprecated in favour of modules that can be found in
3+
the `NumPy`_ and `SciPy`_ libraries.
64
75
.. _NumPy: https://numpy.org
86
.. _SciPy: https://www.scipy.org
@@ -58,6 +56,7 @@
5856
from matplotlib import _api, _docstring, cbook
5957

6058

59+
@_api.deprecated("3.6", alternative="np.hanning")
6160
def window_hanning(x):
6261
"""
6362
Return *x* times the Hanning (or Hann) window of len(*x*).
@@ -69,6 +68,7 @@ def window_hanning(x):
6968
return np.hanning(len(x))*x
7069

7170

71+
@_api.deprecated("3.6", alternative="")
7272
def window_none(x):
7373
"""
7474
No window function; simply return *x*.
@@ -80,6 +80,7 @@ def window_none(x):
8080
return x
8181

8282

83+
@_api.deprecated("3.6", alternative="scipy.signal.detrend")
8384
def detrend(x, key=None, axis=None):
8485
"""
8586
Return *x* with its trend removed.
@@ -129,6 +130,7 @@ def detrend(x, key=None, axis=None):
129130
f"'constant', 'mean', 'linear', or a function")
130131

131132

133+
@_api.deprecated("3.6", alternative="scipy.signal.detrend")
132134
def detrend_mean(x, axis=None):
133135
"""
134136
Return *x* minus the mean(*x*).
@@ -157,6 +159,7 @@ def detrend_mean(x, axis=None):
157159
return x - x.mean(axis, keepdims=True)
158160

159161

162+
@_api.deprecated("3.6", alternative="scipy.signal.detrend")
160163
def detrend_none(x, axis=None):
161164
"""
162165
Return *x*: no detrending.
@@ -179,6 +182,7 @@ def detrend_none(x, axis=None):
179182
return x
180183

181184

185+
@_api.deprecated("3.6", alternative="scipy.signal.detrend")
182186
def detrend_linear(y):
183187
"""
184188
Return *x* minus best fit line; 'linear' detrending.
@@ -531,6 +535,7 @@ def _single_spectrum_helper(
531535
MATLAB compatibility.""")
532536

533537

538+
@_api.deprecated("3.6", alternative="scipy.signal.psd")
534539
@_docstring.dedent_interpd
535540
def psd(x, NFFT=None, Fs=None, detrend=None, window=None,
536541
noverlap=None, pad_to=None, sides=None, scale_by_freq=None):
@@ -587,6 +592,7 @@ def psd(x, NFFT=None, Fs=None, detrend=None, window=None,
587592
return Pxx.real, freqs
588593

589594

595+
@_api.deprecated("3.6", alternative="scipy.signal.csd")
590596
@_docstring.dedent_interpd
591597
def csd(x, y, NFFT=None, Fs=None, detrend=None, window=None,
592598
noverlap=None, pad_to=None, sides=None, scale_by_freq=None):
@@ -688,7 +694,6 @@ def csd(x, y, NFFT=None, Fs=None, detrend=None, window=None,
688694
Can return the complex spectrum of segments within the signal.
689695
"""
690696

691-
692697
complex_spectrum = functools.partial(_single_spectrum_helper, "complex")
693698
complex_spectrum.__doc__ = _single_spectrum_docs.format(
694699
quantity="complex-valued frequency spectrum",
@@ -707,6 +712,7 @@ def csd(x, y, NFFT=None, Fs=None, detrend=None, window=None,
707712
**_docstring.interpd.params)
708713

709714

715+
@_api.deprecated("3.6", alternative="scipy.signal.welch")
710716
@_docstring.dedent_interpd
711717
def specgram(x, NFFT=None, Fs=None, detrend=None, window=None,
712718
noverlap=None, pad_to=None, sides=None, scale_by_freq=None,
@@ -790,6 +796,7 @@ def specgram(x, NFFT=None, Fs=None, detrend=None, window=None,
790796
return spec, freqs, t
791797

792798

799+
@_api.deprecated("3.6", alternative="scipy.signal.coherence")
793800
@_docstring.dedent_interpd
794801
def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none, window=window_hanning,
795802
noverlap=0, pad_to=None, sides='default', scale_by_freq=None):
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

lib/matplotlib/tests/test_axes.py

Lines changed: 0 additions & 250 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,6 @@ def test_label_shift():
134134
assert ax.yaxis.get_label().get_horizontalalignment() == "center"
135135

136136

137-
@check_figures_equal(extensions=["png"])
138-
def test_acorr(fig_test, fig_ref):
139-
np.random.seed(19680801)
140-
Nx = 512
141-
x = np.random.normal(0, 1, Nx).cumsum()
142-
maxlags = Nx-1
143-
144-
ax_test = fig_test.subplots()
145-
ax_test.acorr(x, maxlags=maxlags)
146-
147-
ax_ref = fig_ref.subplots()
148-
# Normalized autocorrelation
149-
norm_auto_corr = np.correlate(x, x, mode="full")/np.dot(x, x)
150-
lags = np.arange(-maxlags, maxlags+1)
151-
norm_auto_corr = norm_auto_corr[Nx-1-maxlags:Nx+maxlags]
152-
ax_ref.vlines(lags, [0], norm_auto_corr)
153-
ax_ref.axhline(y=0, xmin=0, xmax=1)
154-
155-
156137
@check_figures_equal(extensions=["png"])
157138
def test_spy(fig_test, fig_ref):
158139
np.random.seed(19680801)
@@ -4638,237 +4619,6 @@ def test_subplot_key_hash():
46384619
assert ax.get_subplotspec().get_geometry() == (5, 1, 0, 0)
46394620

46404621

4641-
@image_comparison(
4642-
["specgram_freqs.png", "specgram_freqs_linear.png",
4643-
"specgram_noise.png", "specgram_noise_linear.png"],
4644-
remove_text=True, tol=0.07, style="default")
4645-
def test_specgram():
4646-
"""Test axes.specgram in default (psd) mode."""
4647-
4648-
# use former defaults to match existing baseline image
4649-
matplotlib.rcParams['image.interpolation'] = 'nearest'
4650-
4651-
n = 1000
4652-
Fs = 10.
4653-
4654-
fstims = [[Fs/4, Fs/5, Fs/11], [Fs/4.7, Fs/5.6, Fs/11.9]]
4655-
NFFT_freqs = int(10 * Fs / np.min(fstims))
4656-
x = np.arange(0, n, 1/Fs)
4657-
y_freqs = np.concatenate(
4658-
np.sin(2 * np.pi * np.multiply.outer(fstims, x)).sum(axis=1))
4659-
4660-
NFFT_noise = int(10 * Fs / 11)
4661-
np.random.seed(0)
4662-
y_noise = np.concatenate([np.random.standard_normal(n), np.random.rand(n)])
4663-
4664-
all_sides = ["default", "onesided", "twosided"]
4665-
for y, NFFT in [(y_freqs, NFFT_freqs), (y_noise, NFFT_noise)]:
4666-
noverlap = NFFT // 2
4667-
pad_to = int(2 ** np.ceil(np.log2(NFFT)))
4668-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4669-
ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4670-
pad_to=pad_to, sides=sides)
4671-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4672-
ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4673-
pad_to=pad_to, sides=sides,
4674-
scale="linear", norm=matplotlib.colors.LogNorm())
4675-
4676-
4677-
@image_comparison(
4678-
["specgram_magnitude_freqs.png", "specgram_magnitude_freqs_linear.png",
4679-
"specgram_magnitude_noise.png", "specgram_magnitude_noise_linear.png"],
4680-
remove_text=True, tol=0.07, style="default")
4681-
def test_specgram_magnitude():
4682-
"""Test axes.specgram in magnitude mode."""
4683-
4684-
# use former defaults to match existing baseline image
4685-
matplotlib.rcParams['image.interpolation'] = 'nearest'
4686-
4687-
n = 1000
4688-
Fs = 10.
4689-
4690-
fstims = [[Fs/4, Fs/5, Fs/11], [Fs/4.7, Fs/5.6, Fs/11.9]]
4691-
NFFT_freqs = int(100 * Fs / np.min(fstims))
4692-
x = np.arange(0, n, 1/Fs)
4693-
y = np.sin(2 * np.pi * np.multiply.outer(fstims, x)).sum(axis=1)
4694-
y[:, -1] = 1
4695-
y_freqs = np.hstack(y)
4696-
4697-
NFFT_noise = int(10 * Fs / 11)
4698-
np.random.seed(0)
4699-
y_noise = np.concatenate([np.random.standard_normal(n), np.random.rand(n)])
4700-
4701-
all_sides = ["default", "onesided", "twosided"]
4702-
for y, NFFT in [(y_freqs, NFFT_freqs), (y_noise, NFFT_noise)]:
4703-
noverlap = NFFT // 2
4704-
pad_to = int(2 ** np.ceil(np.log2(NFFT)))
4705-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4706-
ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4707-
pad_to=pad_to, sides=sides, mode="magnitude")
4708-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4709-
ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4710-
pad_to=pad_to, sides=sides, mode="magnitude",
4711-
scale="linear", norm=matplotlib.colors.LogNorm())
4712-
4713-
4714-
@image_comparison(
4715-
["specgram_angle_freqs.png", "specgram_phase_freqs.png",
4716-
"specgram_angle_noise.png", "specgram_phase_noise.png"],
4717-
remove_text=True, tol=0.07, style="default")
4718-
def test_specgram_angle():
4719-
"""Test axes.specgram in angle and phase modes."""
4720-
4721-
# use former defaults to match existing baseline image
4722-
matplotlib.rcParams['image.interpolation'] = 'nearest'
4723-
4724-
n = 1000
4725-
Fs = 10.
4726-
4727-
fstims = [[Fs/4, Fs/5, Fs/11], [Fs/4.7, Fs/5.6, Fs/11.9]]
4728-
NFFT_freqs = int(10 * Fs / np.min(fstims))
4729-
x = np.arange(0, n, 1/Fs)
4730-
y = np.sin(2 * np.pi * np.multiply.outer(fstims, x)).sum(axis=1)
4731-
y[:, -1] = 1
4732-
y_freqs = np.hstack(y)
4733-
4734-
NFFT_noise = int(10 * Fs / 11)
4735-
np.random.seed(0)
4736-
y_noise = np.concatenate([np.random.standard_normal(n), np.random.rand(n)])
4737-
4738-
all_sides = ["default", "onesided", "twosided"]
4739-
for y, NFFT in [(y_freqs, NFFT_freqs), (y_noise, NFFT_noise)]:
4740-
noverlap = NFFT // 2
4741-
pad_to = int(2 ** np.ceil(np.log2(NFFT)))
4742-
for mode in ["angle", "phase"]:
4743-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4744-
ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4745-
pad_to=pad_to, sides=sides, mode=mode)
4746-
with pytest.raises(ValueError):
4747-
ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4748-
pad_to=pad_to, sides=sides, mode=mode,
4749-
scale="dB")
4750-
4751-
4752-
def test_specgram_fs_none():
4753-
"""Test axes.specgram when Fs is None, should not throw error."""
4754-
spec, freqs, t, im = plt.specgram(np.ones(300), Fs=None, scale='linear')
4755-
xmin, xmax, freq0, freq1 = im.get_extent()
4756-
assert xmin == 32 and xmax == 96
4757-
4758-
4759-
@check_figures_equal(extensions=["png"])
4760-
def test_specgram_origin_rcparam(fig_test, fig_ref):
4761-
"""Test specgram ignores image.origin rcParam and uses origin 'upper'."""
4762-
t = np.arange(500)
4763-
signal = np.sin(t)
4764-
4765-
plt.rcParams["image.origin"] = 'upper'
4766-
4767-
# Reference: First graph using default origin in imshow (upper),
4768-
fig_ref.subplots().specgram(signal)
4769-
4770-
# Try to overwrite the setting trying to flip the specgram
4771-
plt.rcParams["image.origin"] = 'lower'
4772-
4773-
# Test: origin='lower' should be ignored
4774-
fig_test.subplots().specgram(signal)
4775-
4776-
4777-
def test_specgram_origin_kwarg():
4778-
"""Ensure passing origin as a kwarg raises a TypeError."""
4779-
t = np.arange(500)
4780-
signal = np.sin(t)
4781-
4782-
with pytest.raises(TypeError):
4783-
plt.specgram(signal, origin='lower')
4784-
4785-
4786-
@image_comparison(
4787-
["psd_freqs.png", "csd_freqs.png", "psd_noise.png", "csd_noise.png"],
4788-
remove_text=True, tol=0.002)
4789-
def test_psd_csd():
4790-
n = 10000
4791-
Fs = 100.
4792-
4793-
fstims = [[Fs/4, Fs/5, Fs/11], [Fs/4.7, Fs/5.6, Fs/11.9]]
4794-
NFFT_freqs = int(1000 * Fs / np.min(fstims))
4795-
x = np.arange(0, n, 1/Fs)
4796-
ys_freqs = np.sin(2 * np.pi * np.multiply.outer(fstims, x)).sum(axis=1)
4797-
4798-
NFFT_noise = int(1000 * Fs / 11)
4799-
np.random.seed(0)
4800-
ys_noise = [np.random.standard_normal(n), np.random.rand(n)]
4801-
4802-
all_kwargs = [{"sides": "default"},
4803-
{"sides": "onesided", "return_line": False},
4804-
{"sides": "twosided", "return_line": True}]
4805-
for ys, NFFT in [(ys_freqs, NFFT_freqs), (ys_noise, NFFT_noise)]:
4806-
noverlap = NFFT // 2
4807-
pad_to = int(2 ** np.ceil(np.log2(NFFT)))
4808-
for ax, kwargs in zip(plt.figure().subplots(3), all_kwargs):
4809-
ret = ax.psd(np.concatenate(ys), NFFT=NFFT, Fs=Fs,
4810-
noverlap=noverlap, pad_to=pad_to, **kwargs)
4811-
assert len(ret) == 2 + kwargs.get("return_line", False)
4812-
ax.set(xlabel="", ylabel="")
4813-
for ax, kwargs in zip(plt.figure().subplots(3), all_kwargs):
4814-
ret = ax.csd(*ys, NFFT=NFFT, Fs=Fs,
4815-
noverlap=noverlap, pad_to=pad_to, **kwargs)
4816-
assert len(ret) == 2 + kwargs.get("return_line", False)
4817-
ax.set(xlabel="", ylabel="")
4818-
4819-
4820-
@image_comparison(
4821-
["magnitude_spectrum_freqs_linear.png",
4822-
"magnitude_spectrum_freqs_dB.png",
4823-
"angle_spectrum_freqs.png",
4824-
"phase_spectrum_freqs.png",
4825-
"magnitude_spectrum_noise_linear.png",
4826-
"magnitude_spectrum_noise_dB.png",
4827-
"angle_spectrum_noise.png",
4828-
"phase_spectrum_noise.png"],
4829-
remove_text=True)
4830-
def test_spectrum():
4831-
n = 10000
4832-
Fs = 100.
4833-
4834-
fstims1 = [Fs/4, Fs/5, Fs/11]
4835-
NFFT = int(1000 * Fs / min(fstims1))
4836-
pad_to = int(2 ** np.ceil(np.log2(NFFT)))
4837-
4838-
x = np.arange(0, n, 1/Fs)
4839-
y_freqs = ((np.sin(2 * np.pi * np.outer(x, fstims1)) * 10**np.arange(3))
4840-
.sum(axis=1))
4841-
np.random.seed(0)
4842-
y_noise = np.hstack([np.random.standard_normal(n), np.random.rand(n)]) - .5
4843-
4844-
all_sides = ["default", "onesided", "twosided"]
4845-
kwargs = {"Fs": Fs, "pad_to": pad_to}
4846-
for y in [y_freqs, y_noise]:
4847-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4848-
spec, freqs, line = ax.magnitude_spectrum(y, sides=sides, **kwargs)
4849-
ax.set(xlabel="", ylabel="")
4850-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4851-
spec, freqs, line = ax.magnitude_spectrum(y, sides=sides, **kwargs,
4852-
scale="dB")
4853-
ax.set(xlabel="", ylabel="")
4854-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4855-
spec, freqs, line = ax.angle_spectrum(y, sides=sides, **kwargs)
4856-
ax.set(xlabel="", ylabel="")
4857-
for ax, sides in zip(plt.figure().subplots(3), all_sides):
4858-
spec, freqs, line = ax.phase_spectrum(y, sides=sides, **kwargs)
4859-
ax.set(xlabel="", ylabel="")
4860-
4861-
4862-
def test_psd_csd_edge_cases():
4863-
# Inverted yaxis or fully zero inputs used to throw exceptions.
4864-
axs = plt.figure().subplots(2)
4865-
for ax in axs:
4866-
ax.yaxis.set(inverted=True)
4867-
with np.errstate(divide="ignore"):
4868-
axs[0].psd(np.zeros(5))
4869-
axs[1].csd(np.zeros(5), np.zeros(5))
4870-
4871-
48724622
@check_figures_equal(extensions=['png'])
48734623
def test_twin_remove(fig_test, fig_ref):
48744624
ax_test = fig_test.add_subplot()

0 commit comments

Comments
 (0)