Skip to content

Commit

Permalink
Fix labels
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobachetti committed Oct 5, 2023
1 parent 320dd13 commit 64f8b05
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions stingray/crossspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,23 @@ def plot(
ax2 = None
if np.any(np.iscomplex(self.power)):
ax.plot(self.freq, np.abs(self.power), marker, color="k", label="Amplitude")
ax2 = ax.twinx()

ax2 = ax.twinx()
ax2.tick_params("y", colors="b")
ax2.plot(
self.freq, self.power.imag, marker, color="b", alpha=0.5, label="Imaginary Part"
)

ax.plot(self.freq, self.power.real, marker, color="r", alpha=0.5, label="Real Part")

lines, line_labels = ax.get_legend_handles_labels()
lines2, line_labels2 = ax2.get_legend_handles_labels()
lines = lines + lines2
line_labels = line_labels + line_labels2

else:
ax.plot(self.freq, np.abs(self.power), marker, color="b")
lines, line_labels = ax.get_legend_handles_labels()

xlabel = "Frequency (Hz)"
ylabel = f"Power ({self.norm})"
Expand All @@ -1102,10 +1110,13 @@ def plot(
# x-axis will be labelled.

ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
if ax2 is not None:
ax2.set_ylabel(ylabel)
ax.legend(loc="best")
ax.set_ylabel(ylabel + "-Real")
ax2.set_ylabel(ylabel + "-Imaginary")
else:
ax.set_ylabel(ylabel)

ax.legend(lines, line_labels, loc="best")

if axis is not None:
ax.set_xlim(axis[0:2])
Expand Down

0 comments on commit 64f8b05

Please sign in to comment.