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

Commit4e341cb

Browse files
committed
TST: re-instate tests
1 parent9aea3ed commit4e341cb

28 files changed

+276
-19
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ def acorr(self, x, **kwargs):
19031903
----------
19041904
x : array-like
19051905
1906-
detrend : callable, default:`.mlab.detrend_none` (no detrending)
1906+
detrend : callable, default: no detrending
19071907
A detrending function applied to *x*. It must have the
19081908
signature ::
19091909
@@ -1967,7 +1967,7 @@ def acorr(self, x, **kwargs):
19671967
returnself.xcorr(x,x,**kwargs)
19681968

19691969
@_preprocess_data(replace_names=["x","y"],label_namer="y")
1970-
defxcorr(self,x,y,normed=True,detrend=mlab.detrend_none,
1970+
defxcorr(self,x,y,normed=True,detrend=None,
19711971
usevlines=True,maxlags=10,**kwargs):
19721972
r"""
19731973
Plot the cross correlation between *x* and *y*.
@@ -1980,7 +1980,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
19801980
----------
19811981
x, y : array-like of length n
19821982
1983-
detrend : callable, default:`.mlab.detrend_none` (no detrending)
1983+
detrend : callable, default: no detrending
19841984
A detrending function applied to *x* and *y*. It must have the
19851985
signature ::
19861986
@@ -2045,8 +2045,9 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
20452045
ifNx!=len(y):
20462046
raiseValueError('x and y must be equal length')
20472047

2048-
x=detrend(np.asarray(x))
2049-
y=detrend(np.asarray(y))
2048+
ifdetrendisnotNone:
2049+
x=detrend(np.asarray(x))
2050+
y=detrend(np.asarray(y))
20502051

20512052
correls=np.correlate(x,y,mode="full")
20522053

‎lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,8 +3005,8 @@ def vlines(
30053005
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
30063006
@_copy_docstring_and_deprecators(Axes.xcorr)
30073007
defxcorr(
3008-
x,y,normed=True,detrend=mlab.detrend_none,usevlines=True,
3009-
maxlags=10,*,data=None,**kwargs):
3008+
x,y,normed=True,detrend=None,usevlines=True,maxlags=10,
3009+
*,data=None,**kwargs):
30103010
returngca().xcorr(
30113011
x,y,normed=normed,detrend=detrend,usevlines=usevlines,
30123012
maxlags=maxlags,

‎lib/matplotlib/tests/test_axes.py

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ def test_label_shift():
140140
assertax.yaxis.get_label().get_horizontalalignment()=="center"
141141

142142

143+
@check_figures_equal(extensions=["png"])
144+
deftest_acorr(fig_test,fig_ref):
145+
np.random.seed(19680801)
146+
Nx=512
147+
x=np.random.normal(0,1,Nx).cumsum()
148+
maxlags=Nx-1
149+
150+
ax_test=fig_test.subplots()
151+
ax_test.acorr(x,maxlags=maxlags)
152+
153+
ax_ref=fig_ref.subplots()
154+
# Normalized autocorrelation
155+
norm_auto_corr=np.correlate(x,x,mode="full")/np.dot(x,x)
156+
lags=np.arange(-maxlags,maxlags+1)
157+
norm_auto_corr=norm_auto_corr[Nx-1-maxlags:Nx+maxlags]
158+
ax_ref.vlines(lags, [0],norm_auto_corr)
159+
ax_ref.axhline(y=0,xmin=0,xmax=1)
160+
161+
143162
@check_figures_equal(extensions=["png"])
144163
deftest_spy(fig_test,fig_ref):
145164
np.random.seed(19680801)
@@ -4706,6 +4725,255 @@ def test_subplot_key_hash():
47064725
assertax.get_subplotspec().get_geometry()== (5,1,0,0)
47074726

47084727

4728+
@pytest.mark.filterwarnings(
4729+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4730+
@image_comparison(
4731+
["specgram_freqs.png","specgram_freqs_linear.png",
4732+
"specgram_noise.png","specgram_noise_linear.png"],
4733+
remove_text=True,tol=0.07,style="default")
4734+
deftest_specgram():
4735+
"""Test axes.specgram in default (psd) mode."""
4736+
4737+
# use former defaults to match existing baseline image
4738+
matplotlib.rcParams['image.interpolation']='nearest'
4739+
4740+
n=1000
4741+
Fs=10.
4742+
4743+
fstims= [[Fs/4,Fs/5,Fs/11], [Fs/4.7,Fs/5.6,Fs/11.9]]
4744+
NFFT_freqs=int(10*Fs/np.min(fstims))
4745+
x=np.arange(0,n,1/Fs)
4746+
y_freqs=np.concatenate(
4747+
np.sin(2*np.pi*np.multiply.outer(fstims,x)).sum(axis=1))
4748+
4749+
NFFT_noise=int(10*Fs/11)
4750+
np.random.seed(0)
4751+
y_noise=np.concatenate([np.random.standard_normal(n),np.random.rand(n)])
4752+
4753+
all_sides= ["default","onesided","twosided"]
4754+
fory,NFFTin [(y_freqs,NFFT_freqs), (y_noise,NFFT_noise)]:
4755+
noverlap=NFFT//2
4756+
pad_to=int(2**np.ceil(np.log2(NFFT)))
4757+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4758+
ax.specgram(y,NFFT=NFFT,Fs=Fs,noverlap=noverlap,
4759+
pad_to=pad_to,sides=sides)
4760+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4761+
ax.specgram(y,NFFT=NFFT,Fs=Fs,noverlap=noverlap,
4762+
pad_to=pad_to,sides=sides,
4763+
scale="linear",norm=matplotlib.colors.LogNorm())
4764+
4765+
4766+
@pytest.mark.filterwarnings(
4767+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4768+
@image_comparison(
4769+
["specgram_magnitude_freqs.png","specgram_magnitude_freqs_linear.png",
4770+
"specgram_magnitude_noise.png","specgram_magnitude_noise_linear.png"],
4771+
remove_text=True,tol=0.07,style="default")
4772+
deftest_specgram_magnitude():
4773+
"""Test axes.specgram in magnitude mode."""
4774+
4775+
# use former defaults to match existing baseline image
4776+
matplotlib.rcParams['image.interpolation']='nearest'
4777+
4778+
n=1000
4779+
Fs=10.
4780+
4781+
fstims= [[Fs/4,Fs/5,Fs/11], [Fs/4.7,Fs/5.6,Fs/11.9]]
4782+
NFFT_freqs=int(100*Fs/np.min(fstims))
4783+
x=np.arange(0,n,1/Fs)
4784+
y=np.sin(2*np.pi*np.multiply.outer(fstims,x)).sum(axis=1)
4785+
y[:,-1]=1
4786+
y_freqs=np.hstack(y)
4787+
4788+
NFFT_noise=int(10*Fs/11)
4789+
np.random.seed(0)
4790+
y_noise=np.concatenate([np.random.standard_normal(n),np.random.rand(n)])
4791+
4792+
all_sides= ["default","onesided","twosided"]
4793+
fory,NFFTin [(y_freqs,NFFT_freqs), (y_noise,NFFT_noise)]:
4794+
noverlap=NFFT//2
4795+
pad_to=int(2**np.ceil(np.log2(NFFT)))
4796+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4797+
ax.specgram(y,NFFT=NFFT,Fs=Fs,noverlap=noverlap,
4798+
pad_to=pad_to,sides=sides,mode="magnitude")
4799+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4800+
ax.specgram(y,NFFT=NFFT,Fs=Fs,noverlap=noverlap,
4801+
pad_to=pad_to,sides=sides,mode="magnitude",
4802+
scale="linear",norm=matplotlib.colors.LogNorm())
4803+
4804+
4805+
@pytest.mark.filterwarnings(
4806+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4807+
@image_comparison(
4808+
["specgram_angle_freqs.png","specgram_phase_freqs.png",
4809+
"specgram_angle_noise.png","specgram_phase_noise.png"],
4810+
remove_text=True,tol=0.07,style="default")
4811+
deftest_specgram_angle():
4812+
"""Test axes.specgram in angle and phase modes."""
4813+
4814+
# use former defaults to match existing baseline image
4815+
matplotlib.rcParams['image.interpolation']='nearest'
4816+
4817+
n=1000
4818+
Fs=10.
4819+
4820+
fstims= [[Fs/4,Fs/5,Fs/11], [Fs/4.7,Fs/5.6,Fs/11.9]]
4821+
NFFT_freqs=int(10*Fs/np.min(fstims))
4822+
x=np.arange(0,n,1/Fs)
4823+
y=np.sin(2*np.pi*np.multiply.outer(fstims,x)).sum(axis=1)
4824+
y[:,-1]=1
4825+
y_freqs=np.hstack(y)
4826+
4827+
NFFT_noise=int(10*Fs/11)
4828+
np.random.seed(0)
4829+
y_noise=np.concatenate([np.random.standard_normal(n),np.random.rand(n)])
4830+
4831+
all_sides= ["default","onesided","twosided"]
4832+
fory,NFFTin [(y_freqs,NFFT_freqs), (y_noise,NFFT_noise)]:
4833+
noverlap=NFFT//2
4834+
pad_to=int(2**np.ceil(np.log2(NFFT)))
4835+
formodein ["angle","phase"]:
4836+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4837+
ax.specgram(y,NFFT=NFFT,Fs=Fs,noverlap=noverlap,
4838+
pad_to=pad_to,sides=sides,mode=mode)
4839+
withpytest.raises(ValueError):
4840+
ax.specgram(y,NFFT=NFFT,Fs=Fs,noverlap=noverlap,
4841+
pad_to=pad_to,sides=sides,mode=mode,
4842+
scale="dB")
4843+
4844+
4845+
@pytest.mark.filterwarnings(
4846+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4847+
deftest_specgram_fs_none():
4848+
"""Test axes.specgram when Fs is None, should not throw error."""
4849+
spec,freqs,t,im=plt.specgram(np.ones(300),Fs=None,scale='linear')
4850+
xmin,xmax,freq0,freq1=im.get_extent()
4851+
assertxmin==32andxmax==96
4852+
4853+
4854+
@pytest.mark.filterwarnings(
4855+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4856+
@check_figures_equal(extensions=["png"])
4857+
deftest_specgram_origin_rcparam(fig_test,fig_ref):
4858+
"""Test specgram ignores image.origin rcParam and uses origin 'upper'."""
4859+
t=np.arange(500)
4860+
signal=np.sin(t)
4861+
4862+
plt.rcParams["image.origin"]='upper'
4863+
4864+
# Reference: First graph using default origin in imshow (upper),
4865+
fig_ref.subplots().specgram(signal)
4866+
4867+
# Try to overwrite the setting trying to flip the specgram
4868+
plt.rcParams["image.origin"]='lower'
4869+
4870+
# Test: origin='lower' should be ignored
4871+
fig_test.subplots().specgram(signal)
4872+
4873+
4874+
@pytest.mark.filterwarnings(
4875+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4876+
deftest_specgram_origin_kwarg():
4877+
"""Ensure passing origin as a kwarg raises a TypeError."""
4878+
t=np.arange(500)
4879+
signal=np.sin(t)
4880+
4881+
withpytest.raises(TypeError):
4882+
plt.specgram(signal,origin='lower')
4883+
4884+
4885+
@pytest.mark.filterwarnings(
4886+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4887+
@image_comparison(
4888+
["psd_freqs.png","csd_freqs.png","psd_noise.png","csd_noise.png"],
4889+
remove_text=True,tol=0.002)
4890+
deftest_psd_csd():
4891+
n=10000
4892+
Fs=100.
4893+
4894+
fstims= [[Fs/4,Fs/5,Fs/11], [Fs/4.7,Fs/5.6,Fs/11.9]]
4895+
NFFT_freqs=int(1000*Fs/np.min(fstims))
4896+
x=np.arange(0,n,1/Fs)
4897+
ys_freqs=np.sin(2*np.pi*np.multiply.outer(fstims,x)).sum(axis=1)
4898+
4899+
NFFT_noise=int(1000*Fs/11)
4900+
np.random.seed(0)
4901+
ys_noise= [np.random.standard_normal(n),np.random.rand(n)]
4902+
4903+
all_kwargs= [{"sides":"default"},
4904+
{"sides":"onesided","return_line":False},
4905+
{"sides":"twosided","return_line":True}]
4906+
forys,NFFTin [(ys_freqs,NFFT_freqs), (ys_noise,NFFT_noise)]:
4907+
noverlap=NFFT//2
4908+
pad_to=int(2**np.ceil(np.log2(NFFT)))
4909+
forax,kwargsinzip(plt.figure().subplots(3),all_kwargs):
4910+
ret=ax.psd(np.concatenate(ys),NFFT=NFFT,Fs=Fs,
4911+
noverlap=noverlap,pad_to=pad_to,**kwargs)
4912+
assertlen(ret)==2+kwargs.get("return_line",False)
4913+
ax.set(xlabel="",ylabel="")
4914+
forax,kwargsinzip(plt.figure().subplots(3),all_kwargs):
4915+
ret=ax.csd(*ys,NFFT=NFFT,Fs=Fs,
4916+
noverlap=noverlap,pad_to=pad_to,**kwargs)
4917+
assertlen(ret)==2+kwargs.get("return_line",False)
4918+
ax.set(xlabel="",ylabel="")
4919+
4920+
4921+
@pytest.mark.filterwarnings(
4922+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4923+
@image_comparison(
4924+
["magnitude_spectrum_freqs_linear.png",
4925+
"magnitude_spectrum_freqs_dB.png",
4926+
"angle_spectrum_freqs.png",
4927+
"phase_spectrum_freqs.png",
4928+
"magnitude_spectrum_noise_linear.png",
4929+
"magnitude_spectrum_noise_dB.png",
4930+
"angle_spectrum_noise.png",
4931+
"phase_spectrum_noise.png"],
4932+
remove_text=True)
4933+
deftest_spectrum():
4934+
n=10000
4935+
Fs=100.
4936+
4937+
fstims1= [Fs/4,Fs/5,Fs/11]
4938+
NFFT=int(1000*Fs/min(fstims1))
4939+
pad_to=int(2**np.ceil(np.log2(NFFT)))
4940+
4941+
x=np.arange(0,n,1/Fs)
4942+
y_freqs= ((np.sin(2*np.pi*np.outer(x,fstims1))*10**np.arange(3))
4943+
.sum(axis=1))
4944+
np.random.seed(0)
4945+
y_noise=np.hstack([np.random.standard_normal(n),np.random.rand(n)])-.5
4946+
4947+
all_sides= ["default","onesided","twosided"]
4948+
kwargs= {"Fs":Fs,"pad_to":pad_to}
4949+
foryin [y_freqs,y_noise]:
4950+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4951+
spec,freqs,line=ax.magnitude_spectrum(y,sides=sides,**kwargs)
4952+
ax.set(xlabel="",ylabel="")
4953+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4954+
spec,freqs,line=ax.magnitude_spectrum(y,sides=sides,**kwargs,
4955+
scale="dB")
4956+
ax.set(xlabel="",ylabel="")
4957+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4958+
spec,freqs,line=ax.angle_spectrum(y,sides=sides,**kwargs)
4959+
ax.set(xlabel="",ylabel="")
4960+
forax,sidesinzip(plt.figure().subplots(3),all_sides):
4961+
spec,freqs,line=ax.phase_spectrum(y,sides=sides,**kwargs)
4962+
ax.set(xlabel="",ylabel="")
4963+
4964+
4965+
@pytest.mark.filterwarnings(
4966+
'ignore::matplotlib._api.deprecation.MatplotlibDeprecationWarning')
4967+
deftest_psd_csd_edge_cases():
4968+
# Inverted yaxis or fully zero inputs used to throw exceptions.
4969+
axs=plt.figure().subplots(2)
4970+
foraxinaxs:
4971+
ax.yaxis.set(inverted=True)
4972+
withnp.errstate(divide="ignore"):
4973+
axs[0].psd(np.zeros(5))
4974+
axs[1].csd(np.zeros(5),np.zeros(5))
4975+
4976+
47094977
@check_figures_equal(extensions=['png'])
47104978
deftest_twin_remove(fig_test,fig_ref):
47114979
ax_test=fig_test.add_subplot()

‎pytest.ini

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp