diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index c6cff03b6..eb54109bb 100644 --- a/stingray/lightcurve.py +++ b/stingray/lightcurve.py @@ -1635,9 +1635,10 @@ def plot( if not self.input_counts: flux_attr = "countrate" - return super().plot( + # 1. Let the parent plot the main points (We force witherrors=False so it doesn't try and fail) + ax = super().plot( flux_attr, - witherrors=witherrors, + witherrors=False, labels=labels, ax=ax, title=title, @@ -1648,6 +1649,22 @@ def plot( axis_limits=axis_limits, ) + # 2. Manually plot the error bars ourselves + if witherrors: + err_col = flux_attr + "_err" + # Only try to plot if the error data actually exists + if hasattr(self, err_col): + ax.errorbar( + self.time, + getattr(self, flux_attr), + yerr=getattr(self, err_col), + fmt="none", # "none" means don't draw the dots again (parent already did) + ecolor="k", # Black error bars (optional, but looks standard) + zorder=10 + ) + + return ax + @classmethod def read( cls, filename, fmt=None, format_=None, err_dist="gauss", skip_checks=False, **fits_kwargs