我有一个程序运行良好,但当我试着用按钮来做,当我运行它时,它给了我
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in call
return self.func(*args) File "fire_buttons.py", line 193, in Plot result=la.Graph(grids) File "fire_buttons.py", line 181, in Graph n=sc.shape(data)[2] IndexError: tuple index out of range
其功能是:
def Graph(self,data):
"""Make the plot"""
plt.colormaps()
n=sc.shape(data)[2]
ims=[]
for i in range(n):
mydata=data[:,:,i]
im=plt.imshow(mydata,cmap=plt.get_cmap('jet'))
ims.append([im])
return ims
按钮的一些代码:
^{pr2}$另外,如果我想使用幻灯片小部件,我尝试了如下方法:
self.Tree_entry=Scale(top_frame,from_=0,to=1,orient=HORIZONTAL,length=1000, tickinterval=0.001)
self.Tree_entry.set(40)
我想要从0到1的值,并以0.0001递增,但这只给了我0和1。在
---------------更新------------------
在没有按钮的版本中,我使用的不是绘图功能:
grids=fire(area,Tree,Burning,Lighting,ResistBurn,RegenerateTree,time_step)
result=Graph(grids)
fig=plt.gcf()
ani=ArtistAnimation(fig,result,interval=10,repeat=False)
plt.show()
它运行得很好,所以也许我在情节上出了什么问题?在
您的第一个问题可以通过在
la.Graph(grids)
行中使用grids
的大小来回答。也许它只是一个包含一个项目的元组?(或者至少少于三个,因为[2]
给出了错误。)编辑:
你的第二个问题需要我误解了你想要介于0和1之间。由于将值设置为40,您可能只看到0或1。在to=100
我相信。编辑:以下内容已经过测试。在
您的错误在这一行:
从你提供的证据来看,这与按钮或小部件没有任何关系。您只是试图从元组中获取元素2,但是元组没有那么多元素。你需要找到你定义的地方sc.形状(数据)看看为什么没有你认为的那么多。在
相关问题 更多 >
编程相关推荐