From e29dcbbc07f1c19a8c997cecdacc5a1bfa8071b4 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Tue, 26 Sep 2023 09:36:54 +0200 Subject: [PATCH] Fix plotting of just the relevant part of the spectrum --- stingray/crossspectrum.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/stingray/crossspectrum.py b/stingray/crossspectrum.py index 2156fff51..26d2c7d0c 100644 --- a/stingray/crossspectrum.py +++ b/stingray/crossspectrum.py @@ -1075,9 +1075,14 @@ def plot( fig = plt.figure("crossspectrum") ax = fig.add_subplot(1, 1, 1) - ax.plot(self.freq, np.abs(self.power), marker, color="b", label="Amplitude") - ax.plot(self.freq, self.power.real, marker, color="r", alpha=0.5, label="Real Part") - ax.plot(self.freq, self.power.imag, marker, color="g", alpha=0.5, label="Imaginary Part") + if np.any(np.iscomplex(self.power.imag)): + ax.plot(self.freq, np.abs(self.power), marker, color="b", label="Amplitude") + ax.plot( + self.freq, self.power.imag, marker, color="g", alpha=0.5, label="Imaginary Part" + ) + ax.plot(self.freq, self.power.real, marker, color="r", alpha=0.5, label="Real Part") + else: + ax.plot(self.freq, np.abs(self.power), marker, color="b") if labels is not None: try: @@ -1087,6 +1092,10 @@ def plot( simon("``labels`` must have two labels for x and y axes.") # Not raising here because in case of len(labels)==1, only # x-axis will be labelled. + else: + ax.set_xlabel("Frequency (Hz)") + ax.set_ylabel(f"Power ({self.norm})") + ax.legend(loc="best") if axis is not None: