8000 Fix more edge cases in psd, csd. · matplotlib/matplotlib@e34ba2e · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit e34ba2e

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 a6e01b5 commit e34ba2e

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
@@ -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)
0