0
我想要可視化過濾器的轉換。我想繪製一個散點圖,每隔半秒鐘繪製下一個過濾器的值。'動畫'2D散點圖
我的目標是:
地塊的所有值到點(K),但有值(K)的情節表示。
其中(k)和(k + 1)
疊加在全屏
繪製值之間暫停有情節辦完所有迭代
我做了函數,但效率非常低,在繪製一些值之後,一切都會減慢。
我發現的唯一方法是使用交互式陰謀ion()
,每一步都用更新後的標記重新繪製所有點。對於每一個步驟(k),我想,而刪除先前的點(K-1),並用不同的標記添加他們並添加當前點(K)
import pylab as pl
import time
xPos1 = pl.arange(100)
m1 = [pl.sin(pl.pi*x/10) for x in xPos1]
m2 = [pl.cos(pl.pi*x/30) for x in xPos1]
m3 = [pl.sin(pl.pi*x/20) for x in xPos1]
trueVal1 = [0 for real in xPos1]
def conversionAnim(xPos, trueVal, *args):
mTuple = [arg for arg in args]
colorList = ['Green','Blue','Orchid','Cyan','Goldenrod','Salmon','Orange','Violet','Magenta']
f = pl.figure(figsize =(17,8))
pl.ion()
pl.xlim(min(xPos)-1, max(xPos)+1)
pl.ylim(min(j for i in mTuple for j in i)-.5, max(j for i in mTuple for j in i)+.5)
for i in range(len(xPos)):
print '\ni = %i' % i
for j in range(len(mTuple)):
m = mTuple[j]
mVal = [element for element in m]
print 'Value%i is %s' %(j,mVal[i])
if i == 0:
pl.hold(True)
pl.scatter(xPos[i],mVal[i],s=50, marker = 'o', color = 'Dark'+colorList[j])
pl.plot(xPos[i],trueVal[i])
else:
pl.scatter(xPos[i],mVal[i],s=50, marker = 'o',color = 'Dark'+colorList[j])
pl.scatter(xPos[i-1], mVal[i-1],s=50, marker = 'o', color = 'white')
pl.scatter(xPos[i-1], mVal[i-1],s=50, marker = 'x', color = colorList[j])
pl.plot(xPos[i-1:i+1],trueVal[i-1:i+1], color = 'red')
pl.draw()
time.sleep(.01)
time.sleep(3) # to hold figure after its shown
if __name__ == '__main__':
conversionAnim(xPos1, trueVal1, m1, m2, m3)
我不知道怎麼去解決ion()
並使此功能有效。
@cosmosis感謝您的評論。我最近問了幾個問題,儘管最被接受,但其中一些仍然沒有答案。這就是如何計算驗收的方式。對此無能爲力。 – tomasz74