Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitbeaa1d0

Browse files
committed
MNT: deprecate mlab
.... except for GaussianKDE, which is needed for violinplots
1 parentf8cd2c9 commitbeaa1d0

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
frommatplotlibimport_api,_docstring,cbook
5957

6058

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

7170

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

8282

83+
@_api.deprecated("3.6",alternative="scipy.signal.detrend")
8384
defdetrend(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
defdetrend_mean(x,axis=None):
133135
"""
134136
Return *x* minus the mean(*x*).
@@ -157,6 +159,7 @@ def detrend_mean(x, axis=None):
157159
returnx-x.mean(axis,keepdims=True)
158160

159161

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

181184

185+
@_api.deprecated("3.6",alternative="scipy.signal.detrend")
182186
defdetrend_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
defpsd(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
returnPxx.real,freqs
588593

589594

595+
@_api.deprecated("3.6",alternative="scipy.signal.csd")
590596
@_docstring.dedent_interpd
591597
defcsd(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
defspecgram(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
returnspec,freqs,t
791797

792798

799+
@_api.deprecated("3.6",alternative="scipy.signal.coherence")
793800
@_docstring.dedent_interpd
794801
defcohere(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
assertax.yaxis.get_label().get_horizontalalignment()=="center"
135135

136136

137-
@check_figures_equal(extensions=["png"])
138-
deftest_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
deftest_spy(fig_test,fig_ref):
158139
np.random.seed(19680801)
@@ -4623,237 +4604,6 @@ def test_subplot_key_hash():
46234604
assertax.get_subplotspec().get_geometry()== (5,1,0,0)
46244605

46254606

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp