У меня есть программа, которая работает нормально, но когда я пытаюсь сделать это с помощью кнопок, когда я запускаю ее, она дает мне
Файл "/usr/lib/python2.7/lib-tk/Tkinter.py", строка 1413, в вызов
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
Код для кнопок:
def createWidgets(self):
"""Add widgets to main frame"""
top_frame=Frame(self)
self.Tree=StringVar()
self.Tree_entry=Entry(top_frame,textvariable=self.Tree)
self.label1=Label(top_frame,text="Probability of existence of a tree")
self.Tree_entry.pack(side='right')
self.label1.pack()
top_frame.pack(side=TOP)
......
bottom_frame=Frame(self)
bottom_frame.pack(side=TOP)
self.QUIT=Button(bottom_frame,text='Quit',command=self.quit)
self.QUIT.pack(side=LEFT)
self.operate=Button(bottom_frame,text='Run',command=self.Plot)
self.operate.pack(side=LEFT)
def Plot(self):
if (self.area.get().isdigit() and p.match(self.Tree.get()) and p.match(self.Burning.get()) and p.match(self.Lighting.get()) and p.match(self.ResistBurn.get()) and p.match(self.RegenerateTree.get()) and self.time_step.get().isdigit()):
la=myfire()
grids=la.fire(int(self.area.get()),float(self.Tree.get()),float(self.Burning.get()),float(self.Lighting.get()),float(self.ResistBurn.get()),float(self.RegenerateTree.get()),int(self.time_step.get()))
result=la.Graph(grids)
fig=plt.gcf()
ArtistAnimation(fig,result,interval=10,repeat=False)
plt.show()
Кроме того, если я хочу использовать виджет слайдов, я попробовал что-то вроде:
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.
-------------------- UPDATE --------------------
В версии без кнопок вместо функции Plot я использую:
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()
и все работает нормально, так что, может быть, у меня что-то не так на графике?