-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfancy-curves.py
57 lines (50 loc) · 1.34 KB
/
fancy-curves.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
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import sys
def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
ax = ax if ax is not None else plt.gca()
if color is None:
color = ax._get_lines.color_cycle.next()
if np.isscalar(yerr) or len(yerr) == len(y):
ymin = y - yerr
ymax = y + yerr
elif len(yerr) == 2:
ymin, ymax = yerr
ax.plot(x, y, color=color, linewidth=2)
ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)
ax.set_xlim([0,25000])
def running_average(X, bins):
N=len(X)
New_X = []
for n in range(0,N,bins):
New_X.append(np.mean(X[n:n+bins]))
return np.array(New_X)
def total_dispersion(X, bins):
N=len(X)
New_X = []
for n in range(0,N,bins):
New_X.append(np.sqrt( np.sum( map(lambda x: x**2, X[n:n+bins]) ) ) )
return np.array(New_X)
lines = sys.stdin.readlines()
Data={}
block=0
X=[]; Y=[]; dY=[]
for l in lines:
if "&" not in l:
x, y, dy = map(float, l.split())
X.append(x)
Y.append(y)
dY.append(dy)
else:
Data[block] = np.array([X,Y,dY])
X=[]; Y=[]; dY=[]
block+=1
for n in range(len(Data.keys())):
bins=10
X=Data[n][0][0::bins]
mY = running_average(Data[n][1], bins)
tdY = total_dispersion(Data[n][2], bins)
errorfill(X,mY,tdY)
plt.savefig("test1.png")
plt.show()