나는 사용하고있는 샘플링 속도로 인해 잡음이 많은 음모를 매끄럽게하려고 노력해 왔습니다. 저는 여기에서 도움말을 사용했습니다 - 주로 Plot smooth line with PyPlot ("스플라인"기능을 찾을 수는 없지만 대신 UnivarinteSpline
을 사용하고 있습니다)파이썬에서 그래프를 매끄럽게하는 문제
그러나, 나는 무엇을해도 pyplot 오류 "x and y are not of the same length"
또는 scipi.UnivariateSpline
의 값이 w
인 경우 올바르지 않습니다. 이 문제를 해결하는 방법은 확실하지 않습니다. (실제로 파이썬 인이 아닙니다!) 문제를 야기하는 끝에 플로팅 비트가 있지만 코드를 첨부했습니다. (코드에서 알 수 있듯이 탭으로 구분 된 두 개의리스트) 감사 내용
import os.path
import matplotlib.pyplot as plt
import scipy.interpolate as sci
import numpy as np
def main():
jcc = "0050"
dj = "005"
l = "060"
D = 20
hT = 4 * D
wT1 = 2 * D
wT2 = 5 * D
for jcm in ["025","030","035","040","045","050","055","060"]:
characteristic = "LeadersOnly/Jcm" + jcm + "/Jcc" + jcc + "/dJ" + dj + "/lambda" + l + "/Seed000"
fingertime1 = []
fingertime2 = []
stamp =[]
finger=[]
for x in range(0,2500,50):
if x<10000:
z=("00"+str(x))
if x<1000:
z=("000"+str(x))
if x<100:
z=("0000"+str(x))
if x<10:
z=("00000"+str(x))
stamp.append(x)
path = "LeadersOnly/Jcm" + jcm + "/Jcc" + jcc + "/dJ" + dj + "/lambda" + l + "/Seed000/profile_" + str(z) + ".txt"
if os.path.exists(path):
f = open(path, 'r')
pr1,pr2=np.genfromtxt(path, delimiter='\t', unpack=True)
p1=[]
p2=[]
h1=[]
h2=[]
a1=[]
a2=[]
finger1 = 0
finger2 = 0
for b in range(len(pr1)):
p1.append(pr1[b])
p2.append(pr2[b])
for elem in range(len(pr1)-80):
h1.append((p1[elem + (2*D)]-0.5*(p1[elem]+p1[elem + (4*D)])))
h2.append((p2[elem + (2*D)]-0.5*(p2[elem]+p2[elem + (4*D)])))
if h1[elem] >= hT:
a1.append(1)
else:
a1.append(0)
if h2[elem]>=hT:
a2.append(1)
else:
a2.append(0)
for elem in range(len(a1)-1):
if (a1[elem] - a1[elem + 1]) != 0:
finger1 = finger1 + 1
finger1 = finger1/2
for elem in range(len(a2)-1):
if (a2[elem] - a2[elem + 1]) != 0:
finger2 = finger2 + 1
finger2 = finger2/2
fingertime1.append(finger1)
fingertime2.append(finger2)
finger.append((finger1+finger2)/2)
namegraph = jcm
stampnew = np.linspace(stamp[0],stamp[-1],300)
fingernew = sci.UnivariateSpline(stamp, finger, stampnew)
plt.plot(stampnew,fingernew,label=namegraph)
plt.show()
main()
, 데이터 입력 파일 정수의 목록은 간단하다. 6 자리의 문자열 패딩과 같이 z
정의
0-th dimension must be fixed to 50 but got 300
error Traceback (most recent call last)
/group/data/Cara/JCMMOTFingers/fingercount_jcm_smooth.py in <module>()
116
117 if __name__ == '__main__':
--> 118 main()
119
120
/group/data/Cara/JCMMOTFingers/fingercount_jcm_smooth.py in main()
93 #print(len(stamp))
94 stampnew = np.linspace(stamp[0],stamp[-1],300)
---> 95 fingernew = sci.UnivariateSpline(stamp, finger, stampnew)
96 #print(len(stampnew))
97 #print(len(fingernew))
/usr/lib/python2.6/dist-packages/scipy/interpolate/fitpack2.pyc in __init__(self, x, y, w, bbox, k, s)
86 #_data == x,y,w,xb,xe,k,s,n,t,c,fp,fpint,nrdata,ier
87 data = dfitpack.fpcurf0(x,y,k,w=w,
---> 88 xb=bbox[0],xe=bbox[1],s=s)
89 if data[-1]==1:
90 # nest too small, setting to maximum bound
error: failed in converting 1st keyword `w' of dfitpack.fpcurf0 to C/Fortran array
정확한 추적 복사본을 통과 한 경우 알아낼 수는 있지만 LeadersOnly 폴더 없이는 재생할 수 없습니다. 또한 코드가 실행될 정도로 들여 쓰기를 조정했습니다. –
해결책에 대해 잘 모르겠지만 0- 채우기를 조금 더 멋지게 변경하십시오! z를 초기화하는 줄은 'z ='% 06d '% x' –
으로 바꿀 수 있습니다 ... stampnew = np로 변경하면 다른 것을 얻을 수 있습니다. .linspace (stamp [0], stamp [-1], 50) 그러나 pyplot 함수와 관련하여 이번에는 더 많은 에러를 얻는다. – Cara