2016-07-14 1 views
0

ちょっと私がスライドするときにプロットを更新するスライダーで散布図を作成しようとしています。これはこれまでの私のコードです。それは散布図とスライダを描きますが、私がそれを動かすと何も起こりません。私は問題が.set_ydataビットであると思われますが、私はそれ以外の方法でインターネット上でそれを行う方法を見つけることができないようです。Pythonのスライダーを使ったスキャタープロット

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を使用する必要があります。

# 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) 

おそらくの複製:それは完全に働いたHow to animate a scatter plot?

+0

。どうもありがとうございます :) –

関連する問題