8000 Fix very-edge case in csd(), plus small additional cleanups. · matplotlib/matplotlib@b4253ba · GitHub
[go: up one dir, main page]

Skip to content

Commit b4253ba

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 b4253ba

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7035,12 +7035,9 @@ 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
7039-
intv = vmax - vmin
7040-
logi = int(np.log10(intv))
7041-
if logi == 0:
7042-
logi = .1
7043-
step = 10 * logi
7040+
step = max(10 * int(np.log10(vmax - vmin)), 1)
70447041
ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step)
70457042
self.set_yticks(ticks)
70467043

@@ -7140,11 +7137,9 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
71407137
self.set_xlabel('Frequency')
71417138
self.set_ylabel('Cross Spectrum Magnitude (dB)')
71427139
self.grid(True)
7143-
vmin, vmax = self.viewLim.intervaly
7144-
7145-
intv = vmax - vmin
7146-
step = 10 * int(np.log10(intv))
71477140

7141+
vmin, vmax = self.viewLim.intervaly
7142+
step = max(10 * int(np.log10(vmax - vmin)), 1)
71487143
ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step)
71497144
self.set_yticks(ticks)
71507145

@@ -7576,7 +7571,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
75767571
else:
75777572
Z = 20. * np.log10(spec)
75787573
else:
7579-
raise ValueError('Unknown scale %s', scale)
7574+
raise ValueError(f'Unknown scale {scale!r}')
75807575

75817576
Z = np.flipud(Z)
75827577

0 commit comments

Comments
 (0)
0