3
3
import matplotlib .pyplot as plt
4
4
import numpy as np
5
5
from Chandra .Time import DateTime
6
- from matplotlib . dates import epoch2num , num2epoch
6
+ from cxotime import CxoTime
7
7
from Ska .Matplotlib import plot_cxctime
8
8
9
9
from . import __version__ # noqa
12
12
MAX_TSTOP_UNIX = DateTime ().unix + 1e7
13
13
14
14
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
+
15
23
def get_stat (t0 , t1 , npix ):
16
24
t0 = DateTime (t0 )
17
25
t1 = DateTime (t1 )
@@ -107,16 +115,16 @@ def key_press(self, event):
107
115
zoom = self .zoom if event .key == "p" else 1.0 / self .zoom
108
116
new_x1 = zoom * (x1 - xc ) + xc
109
117
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 )
114
122
115
123
self .ax .set_xlim (new_x0 , new_x1 )
116
124
self .ax .figure .canvas .draw_idle ()
117
125
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 ()
120
128
self .plot_mins = not self .plot_mins
121
129
print (
122
130
"\n Plotting mins and maxes is {}" .format (
@@ -155,8 +163,8 @@ def key_press(self, event):
155
163
156
164
def xlim_changed (self , event ):
157
165
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
160
168
stat = get_stat (self .tstart , self .tstop , self .npix )
161
169
162
170
if (
@@ -174,8 +182,8 @@ def xlim_changed(self, event):
174
182
175
183
def draw_plot (self ):
176
184
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 ()
179
187
180
188
# Force manual y scaling
181
189
scaley = self .scaley
0 commit comments