2016-07-14 12 views
0

안녕하세요 저는 슬라이스를 가로 질러 플롯을 업데이트하는 슬라이더로 분산 형 플롯을 작성하려고합니다. 지금까지 내 코드입니다. 그것은 산란 음모와 슬라이더를 그립니다. 그러나 나는 그것을 움직이면 아무 일도 일어나지 않습니다. 문제가 .set_ydata 비트로 의심되지만 인터넷에서 달리 수행하는 방법을 찾지 못하는 것 같습니다.파이썬에서 슬라이더가있는 분산 형 플롯

import numpy as np 
from matplotlib.widgets import Slider 
from pylab import plot, show, figure, scatter, axes, draw 

fig = figure() 
ax = fig.add_subplot(111) 

x, y = np.random.rand(2,100) 
scat = scatter(x,y) 

axcolor = 'lightgoldenrodyellow' 
axamp = axes([0.2, 0.01, 0.65, 0.03], axisbg=axcolor) 

scorr = Slider(axamp, 'corr', -2,2, valinit=1) 

def update(val): 
    corr = scorr.val 

    for i in range(len(x)): 
     x[i]=x[i]+corr*np.random.randn() 

    for i in range(len(y)): 
     y[i]=y[i]+corr*np.random.randn() 

    scat.set_xdata(x) 
    scat.set_ydata(y) 
    draw() 

scorr.on_changed(update) 

show(scat) 

이것은 공정한 테스트 스크립트 일뿐입니다. 훨씬 복잡한 스크립트로 똑같은 일을해야하지만 더 간단한 문제를 해결하는 것이 더 쉽다는 것을 깨달았습니다. 나는 정말로 단지 scat.set_ydata에 대해 신경을 쓰고 대신 작동하도록 그 대신에 무엇을 넣어야합니까.

미리 감사드립니다.

답변

0

당신은 대신에 set_offsetsset_array를 사용해야합니다 : How to animate a scatter plot?

+0

그것은 완벽하게 작동 :

# make sure you get the right dimensions and direction of arrays here xx = np.vstack ((x, y)) scat.set_offsets (xx.T) # set colors scat.set_array (y) 

은 아마의 중복. 정말 고맙습니다 :) –