Skip to content

Commit

Permalink
remove stickiness of plot attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mpound committed Dec 11, 2023
1 parent 9a7e9e4 commit bff25f8
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/dysh/plot/specplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Plot a spectrum using matplotlib
"""

from copy import deepcopy

import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -98,40 +100,43 @@ def plot(self, **kwargs):
keyword=value arguments (need to describe these in a central place)
"""
# xtype = 'velocity, 'frequency', 'wavelength'
self._plot_kwargs.update(kwargs)
# if self._figure is None:
if True:
self._figure, self._axis = self._plt.subplots(figsize=self._plot_kwargs["figsize"])

# plot arguments for this call of plot(). i.e. non-sticky plot attributes
this_plot_kwargs = deepcopy(self._plot_kwargs)
this_plot_kwargs.update(kwargs)
if True: # @todo deal with plot reuse (notebook vs script)
self._figure, self._axis = self._plt.subplots(figsize=this_plot_kwargs["figsize"])
# else:
# self._axis.cla()

s = self._spectrum
sa = s.spectral_axis
lw = self._plot_kwargs["linewidth"]
xunit = self._plot_kwargs["xaxis_unit"]
yunit = self._plot_kwargs["yaxis_unit"]
lw = this_plot_kwargs["linewidth"]
xunit = this_plot_kwargs["xaxis_unit"]
yunit = this_plot_kwargs["yaxis_unit"]
if xunit is not None:
if "chan" in xunit:
sa = np.arange(len(sa))
self._plot_kwargs["xlabel"] = "Channel"
this_plot_kwargs["xlabel"] = "Channel"
else:
# convert the x axis to the requested
# print(f"EQUIV {equiv} doppler_rest {sa.doppler_rest} [{rfq}] convention {convention}")
# sa = s.spectral_axis.to( self._plot_kwargs["xaxis_unit"], equivalencies=equiv,doppler_rest=rfq, doppler_convention=convention)
sa = s.velocity.to(self._plot_kwargs["xaxis_unit"], equivalencies=s.equivalencies)
self._plot_kwargs["xlabel"] = f"Velocity ({xunit})"
# sa = s.spectral_axis.to( this_plot_kwargs["xaxis_unit"], equivalencies=equiv,doppler_rest=rfq, doppler_convention=convention)
sa = s.velocity.to(this_plot_kwargs["xaxis_unit"], equivalencies=s.equivalencies)
this_plot_kwargs["xlabel"] = f"Velocity ({xunit})"
sf = s.flux
if yunit is not None:
sf = s.flux.to(yunit)
self._axis.plot(sa, sf, color=self._plot_kwargs["color"], lw=lw)
self._axis.set_xlim(self._plot_kwargs["xmin"], self._plot_kwargs["xmax"])
self._axis.set_ylim(self._plot_kwargs["ymin"], self._plot_kwargs["ymax"])
self._axis.plot(sa, sf, color=this_plot_kwargs["color"], lw=lw)
self._axis.set_xlim(this_plot_kwargs["xmin"], this_plot_kwargs["xmax"])
self._axis.set_ylim(this_plot_kwargs["ymin"], this_plot_kwargs["ymax"])
self._axis.tick_params(axis="both", which="both", bottom=True, top=True, left=True, right=True, direction="in")
if self._plot_kwargs["grid"]:
if this_plot_kwargs["grid"]:
self._axis.grid(visible=True, which="major", axis="both", lw=lw / 2, color="k", alpha=0.33)
self._axis.grid(visible=True, which="minor", axis="both", lw=lw / 2, color="k", alpha=0.22, linestyle="--")

self._set_labels(**self._plot_kwargs)
self._set_labels(**this_plot_kwargs)
# self._axis.axhline(y=0,color='red',lw=2)
self.refresh()

Expand Down

0 comments on commit bff25f8

Please sign in to comment.