diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 43705f9..de8ffc4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,8 +4,9 @@ Breaking Changes ---------------- -- The old ``Spectrogram`` class has been removed -- The new ``Spectrogram2`` class has been renamed to ``Spectrogram``. +- The old ``Spectrogram`` class has been removed. (`#76 `__) +- The new ``Spectrogram2`` class has been renamed to ``Spectrogram``. (`#76 `__) +- Adding colorbar functionality to ``plot`` (`#80 `__) 0.4.0 (2022-05-24) ================== diff --git a/radiospectra/mixins.py b/radiospectra/mixins.py index 72f000a..05d44b0 100644 --- a/radiospectra/mixins.py +++ b/radiospectra/mixins.py @@ -16,6 +16,7 @@ def plot(self, axes=None, **kwargs): Returns ------- + `matplotlib.collections.QuadMesh` """ import matplotlib.dates as mdates from matplotlib import pyplot as plt @@ -36,13 +37,19 @@ def plot(self, axes=None, **kwargs): axes.set_title(title) axes.plot(self.times.datetime[[0, -1]], self.frequencies[[0, -1]], linestyle="None", marker="None") - axes.pcolormesh(self.times.datetime, self.frequencies.value, data[:-1, :-1], shading="auto", **kwargs) + ret = axes.pcolormesh(self.times.datetime, self.frequencies.value, data[:-1, :-1], shading="auto", **kwargs) axes.set_xlim(self.times.datetime[0], self.times.datetime[-1]) locator = mdates.AutoDateLocator(minticks=4, maxticks=8) formatter = mdates.ConciseDateFormatter(locator) axes.xaxis.set_major_locator(locator) axes.xaxis.set_major_formatter(formatter) fig.autofmt_xdate() + # Set current axes/image if pyplot is being used (makes colorbar work) + for i in plt.get_fignums(): + if axes in plt.figure(i).axes: + plt.sca(axes) + plt.sci(ret) + return ret class NonUniformImagePlotMixin: diff --git a/radiospectra/spectrogram/sources/eovsa.py b/radiospectra/spectrogram/sources/eovsa.py index c59a85b..84f0b5d 100644 --- a/radiospectra/spectrogram/sources/eovsa.py +++ b/radiospectra/spectrogram/sources/eovsa.py @@ -18,6 +18,7 @@ class EOVSASpectrogram(GenericSpectrogram): >>> spec #doctest: +REMOTE_DATA >>> spec.plot() #doctest: +REMOTE_DATA + """ def __init__(self, data, meta, **kwargs): diff --git a/radiospectra/spectrogram/sources/rstn.py b/radiospectra/spectrogram/sources/rstn.py index 3e733a4..6180665 100644 --- a/radiospectra/spectrogram/sources/rstn.py +++ b/radiospectra/spectrogram/sources/rstn.py @@ -18,6 +18,7 @@ class RSTNSpectrogram(GenericSpectrogram): >>> spec #doctest: +REMOTE_DATA >>> spec.plot() #doctest: +REMOTE_DATA + """ @classmethod diff --git a/radiospectra/spectrogram/spectrogram_factory.py b/radiospectra/spectrogram/spectrogram_factory.py index 8cd5110..80f5554 100644 --- a/radiospectra/spectrogram/spectrogram_factory.py +++ b/radiospectra/spectrogram/spectrogram_factory.py @@ -466,7 +466,7 @@ def _read_idl_sav(file, instrument=None): } return data, meta else: - raise ValueError(f"Unrecognised IDL .sav file: {file}") + raise ValueError(f"Unrecognized IDL .sav file: {file}") Spectrogram = SpectrogramFactory(registry=GenericSpectrogram._registry, default_widget_type=GenericSpectrogram)