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

Skip to content

Commit b0f5888

Browse files
committed
TST: add some tests of antialiasing argument
1 parent 5924668 commit b0f5888

File tree

5 files changed

+169
-89
lines changed

5 files changed

+169
-89
lines changed

lib/matplotlib/image.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,19 @@ def _resample(
180180
# do antialiasing....
181181
# compare the number of displayed pixels of the image to the number of
182182
# the data pixels.
183-
disppixelsX = int(transform.transform([data.shape[1], 0])[0])
184-
disppixelsY = int(transform.transform([data.shape[0], 0])[0])
185-
if ((disppixelsX < 3 * data.shape[1] and
186-
disppixelsX != data.shape[1] and
187-
disppixelsX != 2 * data.shape[1]) or
188-
(disppixelsY < 3 * data.shape[0] and
189-
disppixelsY != data.shape[0] and
190-
disppixelsY != 2 * data.shape[0])):
183+
print(image_obj.origin)
184+
shape = list(data.shape)
185+
if image_obj.origin == 'upper':
186+
shape[0] = 0
187+
dispx, dispy = transform.transform(shape[::-1])
188+
#dispy = transform.transform([data.shape[0], 0])[0]
189+
print('d', dispx, dispy, data.shape[1])
190+
if ((dispx < 3 * data.shape[1] and
191+
dispx != data.shape[1] and
192+
dispx != 2 * data.shape[1]) or
193+
(dispy < 3 * data.shape[0] and
194+
dispy != data.shape[0] and
195+
dispy != 2 * data.shape[0])):
191196
interpolation = 'hanning'
192197
else:
193198
interpolation = 'nearest'

lib/matplotlib/tests/test_axes.py

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ def test_nonfinite_limits():
915915

916916
@image_comparison(['imshow', 'imshow'], remove_text=True, style='mpl20')
917917
def test_imshow():
918+
matplotlib.rcParams['image.interpolation'] = 'nearest'
918919
# Create a NxN image
919920
N = 100
920921
(x, y) = np.indices((N, N))
@@ -936,6 +937,7 @@ def test_imshow():
936937
@image_comparison(['imshow_clip'], style='mpl20')
937938
def test_imshow_clip():
938939
# As originally reported by Gellule Xg <[email protected]>
940+
matplotlib.rcParams['image.interpolation'] = 'nearest'
939941

940942
# Create a NxN image
941943
N = 100
@@ -3733,6 +3735,8 @@ def test_subplot_key_hash():
37333735
remove_text=True, tol=0.07, style='default')
37343736
def test_specgram_freqs():
37353737
'''test axes.specgram in default (psd) mode with sinusoidal stimuli'''
3738+
matplotlib.rcParams['image.interpolation'] = 'nearest'
3739+
37363740
n = 1000
37373741
Fs = 10.
37383742

@@ -3764,30 +3768,30 @@ def test_specgram_freqs():
37643768
ax23 = fig2.add_subplot(3, 1, 3)
37653769

37663770
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3767-
pad_to=pad_to, sides='default', interpolation='nearest')
3771+
pad_to=pad_to, sides='default')
37683772
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3769-
pad_to=pad_to, sides='onesided', interpolation='nearest')
3773+
pad_to=pad_to, sides='onesided')
37703774
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3771-
pad_to=pad_to, sides='twosided', interpolation='nearest')
3775+
pad_to=pad_to, sides='twosided')
37723776

37733777
ax21.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
37743778
pad_to=pad_to, sides='default',
3775-
scale='linear', norm=matplotlib.colors.LogNorm(),
3776-
interpolation='nearest')
3779+
scale='linear', norm=matplotlib.colors.LogNorm())
37773780
ax22.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
37783781
pad_to=pad_to, sides='onesided',
3779-
scale='linear', norm=matplotlib.colors.LogNorm(),
3780-
interpolation='nearest')
3782+
scale='linear', norm=matplotlib.colors.LogNorm())
37813783
ax23.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
37823784
pad_to=pad_to, sides='twosided',
3783-
scale='linear', norm=matplotlib.colors.LogNorm(),
3784-
interpolation='nearest')
3785+
scale='linear', norm=matplotlib.colors.LogNorm())
37853786

37863787

37873788
@image_comparison(['specgram_noise.png', 'specgram_noise_linear.png'],
37883789
remove_text=True, tol=0.01, style='default')
37893790
def test_specgram_noise():
37903791
'''test axes.specgram in default (psd) mode with noise stimuli'''
3792+
3793+
matplotlib.rcParams['image.interpolation'] = 'nearest'
3794+
37913795
np.random.seed(0)
37923796

37933797
n = 1000
@@ -3813,31 +3817,31 @@ def test_specgram_noise():
38133817
ax23 = fig2.add_subplot(3, 1, 3)
38143818

38153819
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3816-
pad_to=pad_to, sides='default', interpolation='nearest')
3820+
pad_to=pad_to, sides='default')
38173821
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3818-
pad_to=pad_to, sides='onesided', interpolation='nearest')
3822+
pad_to=pad_to, sides='onesided')
38193823
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3820-
pad_to=pad_to, sides='twosided', interpolation='nearest')
3824+
pad_to=pad_to, sides='twosided')
38213825

38223826
ax21.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
38233827
pad_to=pad_to, sides='default',
3824-
scale='linear', norm=matplotlib.colors.LogNorm(),
3825-
interpolation='nearest')
3828+
scale='linear', norm=matplotlib.colors.LogNorm())
38263829
ax22.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
38273830
pad_to=pad_to, sides='onesided',
3828-
scale='linear', norm=matplotlib.colors.LogNorm(),
3829-
interpolation='nearest')
3831+
scale='linear', norm=matplotlib.colors.LogNorm())
38303832
ax23.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
38313833
pad_to=pad_to, sides='twosided',
3832-
scale='linear', norm=matplotlib.colors.LogNorm(),
3833-
interpolation='nearest')
3834+
scale='linear', norm=matplotlib.colors.LogNorm())
38343835

38353836

38363837
@image_comparison(['specgram_magnitude_freqs.png',
38373838
'specgram_magnitude_freqs_linear.png'],
38383839
remove_text=True, tol=0.07, style='default')
38393840
def test_specgram_magnitude_freqs():
38403841
'''test axes.specgram in magnitude mode with sinusoidal stimuli'''
3842+
3843+
matplotlib.rcParams['image.interpolation'] = 'nearest'
3844+
38413845
n = 1000
38423846
Fs = 10.
38433847

@@ -3871,34 +3875,30 @@ def test_specgram_magnitude_freqs():
38713875
ax23 = fig2.add_subplot(3, 1, 3)
38723876

38733877
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3874-
pad_to=pad_to, sides='default', mode='magnitude',
3875-
interpolation='nearest')
3878+
pad_to=pad_to, sides='default', mode='magnitude')
38763879
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3877-
pad_to=pad_to, sides='onesided', mode='magnitude',
3878-
interpolation='nearest')
3880+
pad_to=pad_to, sides='onesided', mode='magnitude')
38793881
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3880-
pad_to=pad_to, sides='twosided', mode='magnitude',
3881-
interpolation='nearest')
3882+
pad_to=pad_to, sides='twosided', mode='magnitude')
38823883

38833884
ax21.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
38843885
pad_to=pad_to, sides='default', mode='magnitude',
3885-
scale='linear', norm=matplotlib.colors.LogNorm(),
3886-
interpolation='nearest')
3886+
scale='linear', norm=matplotlib.colors.LogNorm())
38873887
ax22.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
38883888
pad_to=pad_to, sides='onesided', mode='magnitude',
3889-
scale='linear', norm=matplotlib.colors.LogNorm(),
3890-
interpolation='nearest')
3889+
scale='linear', norm=matplotlib.colors.LogNorm())
38913890
ax23.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
38923891
pad_to=pad_to, sides='twosided', mode='magnitude',
3893-
scale='linear', norm=matplotlib.colors.LogNorm(),
3894-
interpolation='nearest')
3892+
scale='linear', norm=matplotlib.colors.LogNorm())
38953893

38963894

38973895
@image_comparison(['specgram_magnitude_noise.png',
38983896
'specgram_magnitude_noise_linear.png'],
38993897
remove_text=True, style='default')
39003898
def test_specgram_magnitude_noise():
39013899
'''test axes.specgram in magnitude mode with noise stimuli'''
3900+
matplotlib.rcParams['image.interpolation'] = 'nearest'
3901+
39023902
np.random.seed(0)
39033903

39043904
n = 1000
@@ -3924,33 +3924,29 @@ def test_specgram_magnitude_noise():
39243924
ax23 = fig2.add_subplot(3, 1, 3)
39253925

39263926
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3927-
pad_to=pad_to, sides='default', mode='magnitude',
3928-
interpolation='nearest')
3927+
pad_to=pad_to, sides='default', mode='magnitude')
39293928
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3930-
pad_to=pad_to, sides='onesided', mode='magnitude',
3931-
interpolation='nearest')
3929+
pad_to=pad_to, sides='onesided', mode='magnitude')
39323930
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3933-
pad_to=pad_to, sides='twosided', mode='magnitude',
3934-
interpolation='nearest')
3931+
pad_to=pad_to, sides='twosided', mode='magnitude')
39353932

39363933
ax21.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
39373934
pad_to=pad_to, sides='default', mode='magnitude',
3938-
scale='linear', norm=matplotlib.colors.LogNorm(),
3939-
interpolation='nearest')
3935+
scale='linear', norm=matplotlib.colors.LogNorm())
39403936
ax22.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
39413937
pad_to=pad_to, sides='onesided', mode='magnitude',
3942-
scale='linear', norm=matplotlib.colors.LogNorm(),
3943-
interpolation='nearest')
3938+
scale='linear', norm=matplotlib.colors.LogNorm())
39443939
ax23.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
39453940
pad_to=pad_to, sides='twosided', mode='magnitude',
3946-
scale='linear', norm=matplotlib.colors.LogNorm(),
3947-
interpolation='nearest')
3941+
scale='linear', norm=matplotlib.colors.LogNorm())
39483942

39493943

39503944
@image_comparison(['specgram_angle_freqs.png'],
39513945
remove_text=True, tol=0.007, style='default')
39523946
def test_specgram_angle_freqs():
39533947
'''test axes.specgram in angle mode with sinusoidal stimuli'''
3948+
matplotlib.rcParams['image.interpolation'] = 'nearest'
3949+
39543950
n = 1000
39553951
Fs = 10.
39563952

@@ -3979,35 +3975,34 @@ def test_specgram_angle_freqs():
39793975
ax13 = fig1.add_subplot(3, 1, 3)
39803976

39813977
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3982-
pad_to=pad_to, sides='default', mode='angle',
3983-
interpolation='nearest')
3978+
pad_to=pad_to, sides='default', mode='angle')
39843979
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3985-
pad_to=pad_to, sides='onesided', mode='angle',
3986-
interpolation='nearest')
3980+
pad_to=pad_to, sides='onesided', mode='angle')
39873981
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
3988-
pad_to=pad_to, sides='twosided', mode='angle',
3989-
interpolation='nearest')
3982+
pad_to=pad_to, sides='twosided', mode='angle')
39903983

39913984
with pytest.raises(ValueError):
39923985
ax11.specgram(y, NFFT=NFFT, Fs=Fs,
39933986
noverlap=noverlap, pad_to=pad_to, sides='default',
3994-
mode='phase', scale='dB', interpolation='nearest')
3987+
mode='phase', scale='dB')
39953988

39963989
with pytest.raises(ValueError):
39973990
ax12.specgram(y, NFFT=NFFT, Fs=Fs,
39983991
noverlap=noverlap, pad_to=pad_to, sides='onesided',
3999-
mode='phase', scale='dB', interpolation='nearest')
3992+
mode='phase', scale='dB')
40003993

40013994
with pytest.raises(ValueError):
40023995
ax13.specgram(y, NFFT=NFFT, Fs=Fs,
40033996
noverlap=noverlap, pad_to=pad_to, sides='twosided',
4004-
mode='phase', scale='dB', interpolation='nearest')
3997+
mode='phase', scale='dB')
40053998

40063999

40074000
@image_comparison(['specgram_angle_noise.png'],
40084001
remove_text=True, style='default')
40094002
def test_specgram_noise_angle():
40104003
'''test axes.specgram in angle mode with noise stimuli'''
4004+
matplotlib.rcParams['image.interpolation'] = 'nearest'
4005+
40114006
np.random.seed(0)
40124007

40134008
n = 1000
@@ -4028,35 +4023,33 @@ def test_specgram_noise_angle():
40284023
ax13 = fig1.add_subplot(3, 1, 3)
40294024

40304025
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4031-
pad_to=pad_to, sides='default', mode='angle',
4032-
interpolation='nearest')
4026+
pad_to=pad_to, sides='default', mode='angle')
40334027
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4034-
pad_to=pad_to, sides='onesided', mode='angle',
4035-
interpolation='nearest')
4028+
pad_to=pad_to, sides='onesided', mode='angle')
40364029
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4037-
pad_to=pad_to, sides='twosided', mode='angle',
4038-
interpolation='nearest')
4030+
pad_to=pad_to, sides='twosided', mode='angle')
40394031

40404032
with pytest.raises(ValueError):
40414033
ax11.specgram(y, NFFT=NFFT, Fs=Fs,
40424034
noverlap=noverlap, pad_to=pad_to, sides='default',
4043-
mode='phase', scale='dB', interpolation='nearest')
4035+
mode='phase', scale='dB')
40444036

40454037
with pytest.raises(ValueError):
40464038
ax12.specgram(y, NFFT=NFFT, Fs=Fs,
40474039
noverlap=noverlap, pad_to=pad_to, sides='onesided',
4048-
mode='phase', scale='dB', interpolation='nearest')
4040+
mode='phase', scale='dB')
40494041

40504042
with pytest.raises(ValueError):
40514043
ax13.specgram(y, NFFT=NFFT, Fs=Fs,
40524044
noverlap=noverlap, pad_to=pad_to, sides='twosided',
4053-
mode='phase', scale='dB', interpolation='nearest')
4045+
mode='phase', scale='dB')
40544046

40554047

40564048
@image_comparison(['specgram_phase_freqs.png'],
40574049
remove_text=True, style='default')
40584050
def test_specgram_freqs_phase():
40594051
'''test axes.specgram in phase mode with sinusoidal stimuli'''
4052+
matplotlib.rcParams['image.interpolation'] = 'nearest'
40604053
n = 1000
40614054
Fs = 10.
40624055

@@ -4085,35 +4078,33 @@ def test_specgram_freqs_phase():
40854078
ax13 = fig1.add_subplot(3, 1, 3)
40864079

40874080
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4088-
pad_to=pad_to, sides='default', mode='phase',
4089-
interpolation='nearest')
4081+
pad_to=pad_to, sides='default', mode='phase')
40904082
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4091-
pad_to=pad_to, sides='onesided', mode='phase',
4092-
interpolation='nearest')
4083+
pad_to=pad_to, sides='onesided', mode='phase')
40934084
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4094-
pad_to=pad_to, sides='twosided', mode='phase',
4095-
interpolation='nearest')
4085+
pad_to=pad_to, sides='twosided', mode='phase')
40964086

40974087
with pytest.raises(ValueError):
40984088
ax11.specgram(y, NFFT=NFFT, Fs=Fs,
40994089
noverlap=noverlap, pad_to=pad_to, sides='default',
4100-
mode='phase', scale='dB', interpolation='nearest')
4090+
mode='phase', scale='dB')
41014091

41024092
with pytest.raises(ValueError):
41034093
ax12.specgram(y, NFFT=NFFT, Fs=Fs,
41044094
noverlap=noverlap, pad_to=pad_to, sides='onesided',
4105-
mode='phase', scale='dB', interpolation='nearest')
4095+
mode='phase', scale='dB')
41064096

41074097
with pytest.raises(ValueError):
41084098
ax13.specgram(y, NFFT=NFFT, Fs=Fs,
41094099
noverlap=noverlap, pad_to=pad_to, sides='twosided',
4110-
mode='phase', scale='dB', interpolation='nearest')
4100+
mode='phase', scale='dB')
41114101

41124102

41134103
@image_comparison(['specgram_phase_noise.png'],
41144104
remove_text=True, style='default')
41154105
def test_specgram_noise_phase():
41164106
'''test axes.specgram in phase mode with noise stimuli'''
4107+
matplotlib.rcParams['image.interpolation'] = 'nearest'
41174108
np.random.seed(0)
41184109

41194110
n = 1000
@@ -4134,29 +4125,26 @@ def test_specgram_noise_phase():
41344125
ax13 = fig1.add_subplot(3, 1, 3)
41354126

41364127
ax11.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4137-
pad_to=pad_to, sides='default', mode='phase',
4138-
interpolation='nearest')
4128+
pad_to=pad_to, sides='default', mode='phase')
41394129
ax12.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4140-
pad_to=pad_to, sides='onesided', mode='phase',
4141-
interpolation='nearest')
4130+
pad_to=pad_to, sides='onesided', mode='phase')
41424131
ax13.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
4143-
pad_to=pad_to, sides='twosided', mode='phase',
4144-
interpolation='nearest')
4132+
pad_to=pad_to, sides='twosided', mode='phase')
41454133

41464134
with pytest.raises(ValueError):
41474135
ax11.specgram(y, NFFT=NFFT, Fs=Fs,
41484136
noverlap=noverlap, pad_to=pad_to, sides='default',
4149-
mode='phase', scale='dB', interpolation='nearest')
4137+
mode='phase', scale='dB')
41504138

41514139
with pytest.raises(ValueError):
41524140
ax12.specgram(y, NFFT=NFFT, Fs=Fs,
41534141
noverlap=noverlap, pad_to=pad_to, sides='onesided',
4154-
mode='phase', scale='dB', interpolation='nearest')
4142+
mode='phase', scale='dB')
41554143

41564144
with pytest.raises(ValueError):
41574145
ax13.specgram(y, NFFT=NFFT, Fs=Fs,
41584146
noverlap=noverlap, pad_to=pad_to, sides='twosided',
4159-
mode='phase', scale='dB', interpolation='nearest')
4147+
mode='phase', scale='dB')
41604148

41614149

41624150
@image_comparison(['psd_freqs.png'], remove_text=True)

0 commit comments

Comments
 (0)