1

いくつかの配列 (x、y、および a、x& y は座標、a は温度) に基づいて温度マップを作成しました。私はそれにスライダーバーを追加しようとしていて、取得し続けています

 TypeError: Input z must be a 2D array.

スライダーを使おうとすると。最初のグラフは正しいです。元の入力と更新への入力は、1 つの変数 (配列の行) を除いて同一であることがわかります。

a=np.array(Matrix)    #contains all temperatures, approx. 2000 points*4 sensors
a0=a[0]               #first set of temperatures
x=np.array([0,0,2,2])
y=np.array([0,2,0,2])

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)

xi, yi = np.mgrid[x.min():x.max():500j, y.min():y.max():500j]
zi = griddata(x,y,a0,xi,yi, interp='linear')

CS = plt.contourf(xi,yi,zi,50,cmap='hsv_r', vmax=M, vmin=m)
plt.colorbar(CS)
plt.scatter(x,y,marker='o',c='none',s=128, lw=1,zorder=10)

ax.scatter(x, y, c='none', s=64, lw=0)
ax.set(xlabel='X', ylabel='Y', title='Title')

axsigma  = p.axes([0.25, 0.10, 0.65, 0.03], axisbg='#A5D3FF') 
slider1 = Slider (axsigma, 'Datapoint',0, datapoints-2,  valinit=0,  valfmt='%0.f', dragging=True,  fc='#1E90FF')

canvas1=axsigma.figure.canvas

def update (val):
    val=int(val)
    new=a[val]
    canvas1.blit(axsigma.bbox)
    ax.scatter(x, y, c='none', s=128, lw=.1)
    zi = griddata(x,y,new,xi,yi, interp='linear')
    CS = plt.contourf(xi,yi,zi,50,cmap='hsv', vmax=M, vmin=m)    

slider1.on_changed(update)

どんな助けでも大歓迎です!

編集

追加する

a=np.array([[6.7, 6.5, 5.9, 6.0], [4.7, 4.7, 4.2, 4.2], [5.1, 5.2, 5.5, 4.9]])
M=a.max()
m=a.min()
datapoints=len(a)

実行するのに十分な情報を提供する必要があります。in withinに変更newすることで、エラーは解消されますが、スライダーはまだグラフを調整しませんziCSdef update

4

1 に答える 1

1

実行可能な例を提供しなかったため、推測することしかできません。あなたが投稿したものの1つの問題はupdate、余分なアーティストを描画するのではなく、プロットしたアーティストを実際に更新したい関数です。の線に沿った何か

...
scat = ax.scatter(x, y, c='none', s=64, lw=0)
...

その後

def update(val):
   ...
   scat.set_paths(...)  # update the artist
   ...
   ax.draw()   # redraw the axes
于 2013-07-12T19:07:23.130 に答える