Skip to content

Commit 53edb19

Browse files
committed
Fix very-edge case in csd(), plus small additional cleanups.
Previously, `csd([0, 0], [0, 0])` would fail with a ZeroDivisionError when computing yticks. Fix that by copying the logic from psd, and streamlining it in both places. Also fix an unformatted exception message in specgram.
1 parent 7c2a3c4 commit 53edb19

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7035,12 +7035,11 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
70357035
self.set_xlabel('Frequency')
70367036
self.set_ylabel('Power Spectral Density (%s)' % psd_units)
70377037
self.grid(True)
7038+
70387039
vmin, vmax = self.viewLim.intervaly
70397040
intv = vmax - vmin
70407041
logi = int(np.log10(intv))
7041-
if logi == 0:
7042-
logi = .1
7043-
step = 10 * logi
7042+
step = max(10 * int(np.log10(intv)), 1)
70447043
ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step)
70457044
self.set_yticks(ticks)
70467045

@@ -7140,11 +7139,10 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
71407139
self.set_xlabel('Frequency')
71417140
self.set_ylabel('Cross Spectrum Magnitude (dB)')
71427141
self.grid(True)
7143-
vmin, vmax = self.viewLim.intervaly
71447142

7143+
vmin, vmax = self.viewLim.intervaly
71457144
intv = vmax - vmin
7146-
step = 10 * int(np.log10(intv))
7147-
7145+
step = max(10 * int(np.log10(intv)), 1)
71487146
ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step)
71497147
self.set_yticks(ticks)
71507148

@@ -7576,7 +7574,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
75767574
else:
75777575
Z = 20. * np.log10(spec)
75787576
else:
7579-
raise ValueError('Unknown scale %s', scale)
7577+
raise ValueError('Unknown scale {scale!r}')
75807578

75817579
Z = np.flipud(Z)
75827580

0 commit comments

Comments
 (0)