Skip to content

Commit 3065bf7

Browse files
committedJan 15, 2025·
Fix Msid.plot
1 parent bdedefa commit 3065bf7

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed
 

‎cheta/plot.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import matplotlib.pyplot as plt
44
import numpy as np
55
from Chandra.Time import DateTime
6-
from matplotlib.dates import epoch2num, num2epoch
6+
from cxotime import CxoTime
77
from Ska.Matplotlib import plot_cxctime
88

99
from . import __version__ # noqa
@@ -12,6 +12,14 @@
1212
MAX_TSTOP_UNIX = DateTime().unix + 1e7
1313

1414

15+
def unix_to_plot_date(epoch):
16+
return CxoTime(epoch, format="unix").plot_date
17+
18+
19+
def plot_date_to_unix(num):
20+
return CxoTime(num, format="plot_date").unix
21+
22+
1523
def get_stat(t0, t1, npix):
1624
t0 = DateTime(t0)
1725
t1 = DateTime(t1)
@@ -107,16 +115,16 @@ def key_press(self, event):
107115
zoom = self.zoom if event.key == "p" else 1.0 / self.zoom
108116
new_x1 = zoom * (x1 - xc) + xc
109117
new_x0 = new_x1 - zoom * dx
110-
tstart = max(num2epoch(new_x0), MIN_TSTART_UNIX)
111-
tstop = min(num2epoch(new_x1), MAX_TSTOP_UNIX)
112-
new_x0 = epoch2num(tstart)
113-
new_x1 = epoch2num(tstop)
118+
tstart = max(plot_date_to_unix(new_x0), MIN_TSTART_UNIX)
119+
tstop = min(plot_date_to_unix(new_x1), MAX_TSTOP_UNIX)
120+
new_x0 = unix_to_plot_date(tstart)
121+
new_x1 = unix_to_plot_date(tstop)
114122

115123
self.ax.set_xlim(new_x0, new_x1)
116124
self.ax.figure.canvas.draw_idle()
117125
elif event.key == "m":
118-
for _ in range(len(self.ax.lines)):
119-
self.ax.lines.pop()
126+
for line in self.ax.lines:
127+
line.remove()
120128
self.plot_mins = not self.plot_mins
121129
print(
122130
"\nPlotting mins and maxes is {}".format(
@@ -155,8 +163,8 @@ def key_press(self, event):
155163

156164
def xlim_changed(self, event):
157165
x0, x1 = self.ax.get_xlim()
158-
self.tstart = DateTime(num2epoch(x0), format="unix").secs
159-
self.tstop = DateTime(num2epoch(x1), format="unix").secs
166+
self.tstart = DateTime(plot_date_to_unix(x0), format="unix").secs
167+
self.tstop = DateTime(plot_date_to_unix(x1), format="unix").secs
160168
stat = get_stat(self.tstart, self.tstop, self.npix)
161169

162170
if (
@@ -174,8 +182,8 @@ def xlim_changed(self, event):
174182

175183
def draw_plot(self):
176184
msid = self.msid
177-
for _ in range(len(self.ax.lines)):
178-
self.ax.lines.pop()
185+
for line in self.ax.lines:
186+
line.remove()
179187

180188
# Force manual y scaling
181189
scaley = self.scaley

0 commit comments

Comments
 (0)
Please sign in to comment.