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

Skip to content

Commit 2cd1846

Browse files
committed
Fix more edge cases in psd, csd.
intervaly would not be ordered if the yaxis is inverted; get_ybound() is always ordered. Fix that, add a test, and also test the full-zero input case recently fixed.
1 parent c7064d3 commit 2cd1846

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

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
@@ -4671,6 +4671,16 @@ def test_spectrum():
46714671
ax.set(xlabel="", ylabel="")
46724672

46734673

4674+
def test_psd_csd_edge_cases():
4675+
# Inverted yaxis or fully zero inputs used to throw exceptions.
4676+
axs = plt.figure().subplots(2)
4677+
for ax in axs:
4678+
ax.yaxis.set(inverted=True)
4679+
with np.errstate(divide="ignore"):
4680+
axs[0].psd(np.zeros(5))
4681+
axs[1].csd(np.zeros(5), np.zeros(5))
4682+
4683+
46744684
@check_figures_equal(extensions=['png'])
46754685
def test_twin_remove(fig_test, fig_ref):
46764686
ax_test = fig_test.add_subplot()

0 commit comments

Comments
 (0)