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

Skip to content

Commit c0fc2bb

Browse files
authored
Merge pull request #21217 from meeseeksmachine/auto-backport-of-pr-21215-on-v3.5.x
Backport PR #21215 on branch v3.5.x (Fix more edge cases in psd, csd.)
2 parents f95c5cd + 8f2bd97 commit c0fc2bb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7042,7 +7042,7 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
70427042
self.set_ylabel('Power Spectral Density (%s)' % psd_units)
70437043
self.grid(True)
70447044

7045-
vmin, vmax = self.viewLim.intervaly
7045+
vmin, vmax = self.get_ybound()
70467046
step = max(10 * int(np.log10(vmax - vmin)), 1)
70477047
ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step)
70487048
self.set_yticks(ticks)
@@ -7144,7 +7144,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
71447144
self.set_ylabel('Cross Spectrum Magnitude (dB)')
71457145
self.grid(True)
71467146

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

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4664,6 +4664,16 @@ def test_spectrum():
46644664
ax.set(xlabel="", ylabel="")
46654665

46664666

4667+
def test_psd_csd_edge_cases():
4668+
# Inverted yaxis or fully zero inputs used to throw exceptions.
4669+
axs = plt.figure().subplots(2)
4670+
for ax in axs:
4671+
ax.yaxis.set(inverted=True)
4672+
with np.errstate(divide="ignore"):
4673+
axs[0].psd(np.zeros(5))
4674+
axs[1].csd(np.zeros(5), np.zeros(5))
4675+
4676+
46674677
@check_figures_equal(extensions=['png'])
46684678
def test_twin_remove(fig_test, fig_ref):
46694679
ax_test = fig_test.add_subplot()

0 commit comments

Comments
 (0)