-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspan.py
177 lines (156 loc) · 3.99 KB
/
span.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python
"""
The SpanSelector is a mouse widget to select a xmin/xmax range and plot the
detail view of the selected region in the lower axes
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime as dt
import numpy as np
from sys import stdout
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import RadioButtons
steady = []
steadys = []
steadye = []
unsteady = []
unsteadye = []
unsteadys = []
arrs = 0
arre = 0
result = []
final = []
re = []
def hzfunc(label):
hzdict = {'Mark Steady': highlight ,'Mark Unsteady':dehighlight}
global func
func=hzdict[label]
def in_take(xmin,xmax):
global func
func(xmin,xmax)
# arrs = result[::2]
# arre = result[1::2]
# if type == 0 :
# arrs.append(xmin)
# arre.append(xmax)
# else :
# arre.append(xmin)
# arrs.append(xmax)
# final = arrs + arre
# final.sort()
# idx = 0
# scount = 0
#
# for i in (0,len(final)):
# if (-1 != arrs.index(final[i])):
# idx+=-1
# else:
# idx+=1
# if (-1 == idx and scount == 0):
# SS.append(final[i])
# scount = 1
# if (idx ==0 and scount == 1):
# scount = 0
# SS.append(final[i])
# print SS
#
def onselect(xmin, xmax):
indmin, indmax = np.searchsorted(x, (xmin, xmax))
indmax = min(len(x)-1, indmax)
thisx = x[indmin:indmax]
thisy = y[indmin:indmax]
line2.set_data(thisx, thisy)
ax2.set_xlim(thisx[0], thisx[-1])
ax2.set_ylim(thisy.min(), thisy.max())
fig.canvas.draw()
def highlight(xmin, xmax):
indmin, indmax = np.searchsorted(x, (xmin, xmax))
indmax = min(len(x)-1, indmax)
thisx = x[indmin:indmax]
ax.axvspan(thisx[0], thisx[-1], color='yellow', alpha=1)
ax2.axvspan(thisx[0], thisx[-1], color='yellow', alpha=1)
steadyxmin = thisx[0]
steadyxmax = thisx[-1]
steady.append(steadyxmin)
steadys.append(steadyxmin)
steady.append(steadyxmax)
steadye.append(steadyxmax)
fig.canvas.draw()
type = 0
#fitdata(xmin,xmax,0)
def dehighlight(xmin, xmax):
indmin, indmax = np.searchsorted(x, (xmin, xmax))
indmax = min(len(x)-1, indmax)
thisx = x[indmin:indmax]
ax.axvspan(thisx[0], thisx[-1], color='white', alpha=1)
ax2.axvspan(thisx[0], thisx[-1], color='white', alpha=1)
steadyxmin = thisx[0]
steadyxmax = thisx[-1]
unsteadys.append(steadyxmin)
unsteady.append(steadyxmin)
unsteady.append(steadyxmax)
unsteadye.append(steadyxmax)
fig.canvas.draw()
type = 1
#fitdata(xmin,xmax,1)
# set useblit True on gtkagg for enhanced performance
if __name__=='__main__':
fig = plt.figure(figsize=(15,10))
ax = fig.add_subplot(211, axisbg='white')
x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))
ax.plot(x, y, '-')
ax.set_ylim(-2,2)
ax.set_title('Press left mouse button and Drag to Magnify in the Zoom Window')
ax2 = fig.add_subplot(212, axisbg='white')
line2,=ax2.plot(x, y, '-')
ax2.set_title('Zoom Window')
axcolor = 'white'
rax = plt.axes([0.905, 0.01, 0.1, 0.1], axisbg=axcolor)
radio = RadioButtons(rax, ('Mark Steady', 'Mark Unsteady'))
radio.on_clicked(hzfunc)
span = SpanSelector(ax, onselect, 'horizontal', useblit=True,rectprops=dict(alpha=0.5, facecolor='red') )
#print span
#print dir(span)
func=highlight
span1 = SpanSelector(ax2, in_take, 'horizontal', useblit=True,rectprops=dict(alpha=0.5) )
plt.show()
c = 0
k = 0
steady.sort()
for i in steady:
if i in steadys:
c-=1
else:
c+=1
if ( c==-1 and k==0):
temp = i
result.append(temp)
k+=1
if c==0 :
k=0
result.append(i)
arrs = result [::2]
arre = result [1::2]
result1 = result
final = result1 + unsteady
final.sort()
c=0
k=0
for j in final:
if j in unsteadys or j in arre:
c+=1
else:
c+=-1
if (c==-1 and k==0):
temp = i
re.append(i)
k+=1
if c==0:
k=0
re.append(i)
print re