Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7042,7 +7042,7 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
self.set_ylabel('Power Spectral Density (%s)' % psd_units)
self.grid(True)

vmin, vmax = self.viewLim.intervaly
vmin, vmax = self.get_ybound()
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 @@ -7144,7 +7144,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
self.set_ylabel('Cross Spectrum Magnitude (dB)')
self.grid(True)

vmin, vmax = self.viewLim.intervaly
vmin, vmax = self.get_ybound()
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
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4664,6 +4664,16 @@ def test_spectrum():
ax.set(xlabel="", ylabel="")


def test_psd_csd_edge_cases():
# Inverted yaxis or fully zero inputs used to throw exceptions.
axs = plt.figure().subplots(2)
for ax in axs:
ax.yaxis.set(inverted=True)
with np.errstate(divide="ignore"):
axs[0].psd(np.zeros(5))
axs[1].csd(np.zeros(5), np.zeros(5))


@check_figures_equal(extensions=['png'])
def test_twin_remove(fig_test, fig_ref):
ax_test = fig_test.add_subplot()
Expand Down