Skip to content

Commit

Permalink
Fix plotting of just the relevant part of the spectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobachetti committed Sep 26, 2023
1 parent d2df1ee commit e29dcbb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions stingray/crossspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 1080 in stingray/crossspectrum.py

View check run for this annotation

Codecov / codecov/patch

stingray/crossspectrum.py#L1078-L1080

Added lines #L1078 - L1080 were not covered by tests
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")

Check warning on line 1083 in stingray/crossspectrum.py

View check run for this annotation

Codecov / codecov/patch

stingray/crossspectrum.py#L1083

Added line #L1083 was not covered by tests
else:
ax.plot(self.freq, np.abs(self.power), marker, color="b")

Check warning on line 1085 in stingray/crossspectrum.py

View check run for this annotation

Codecov / codecov/patch

stingray/crossspectrum.py#L1085

Added line #L1085 was not covered by tests

if labels is not None:
try:
Expand All @@ -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})")

Check warning on line 1097 in stingray/crossspectrum.py

View check run for this annotation

Codecov / codecov/patch

stingray/crossspectrum.py#L1096-L1097

Added lines #L1096 - L1097 were not covered by tests

ax.legend(loc="best")

if axis is not None:
Expand Down

0 comments on commit e29dcbb

Please sign in to comment.