Skip to content

Backport PR #21191 on branch v3.5.x (Fix very-edge case in csd(), plus small additional cleanups.) #21210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7041,12 +7041,9 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
self.set_xlabel('Frequency')
self.set_ylabel('Power Spectral Density (%s)' % psd_units)
self.grid(True)

vmin, vmax = self.viewLim.intervaly
intv = vmax - vmin
logi = int(np.log10(intv))
if logi == 0:
logi = .1
step = 10 * logi
step = max(10 * int(np.log10(vmax - vmin)), 1)
ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step)
self.set_yticks(ticks)

Expand Down Expand Up @@ -7146,11 +7143,9 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
self.set_xlabel('Frequency')
self.set_ylabel('Cross Spectrum Magnitude (dB)')
self.grid(True)
vmin, vmax = self.viewLim.intervaly

intv = vmax - vmin
step = 10 * int(np.log10(intv))

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

Expand Down Expand Up @@ -7582,7 +7577,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
else:
Z = 20. * np.log10(spec)
else:
raise ValueError('Unknown scale %s', scale)
raise ValueError(f'Unknown scale {scale!r}')

Z = np.flipud(Z)

Expand Down