Me and my team are almost to the finishing point. Our final problem is
getting the graph to update.
When we run the graph the get the following issue: "
Traceback (most recent call last):
File "/home/gnelson/scc08whole/branch/realistic2d/gtkgui.py", line 100, in
update
self.ax.draw_artist(plt.contourf)
File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 1535, in
draw_artist
a.draw(self._cachedRenderer)
AttributeError: 'function' object has no attribute 'draw'"
Our Code is at: " http://code.google.com/p/scc08/ "
and we are using the gtkgui.py
import time
import gtk, gobject
import matplotlib
matplotlib.use('GTKAgg')
import matplotlib.pyplot as plt
from driver import Driver
import numpy as np
class Gui:
def updateData(self):
self.updateTemps()
self.getMats()
self.addTimeSteps()
self.getAirPts()
self.getGroundPts()
self.getBridgePts()
def updateTemps(self):
self.temps = []
temp = self.dr.myGrid.fields
for i in range(len(temp)):
self.temps.append([])
for j in range(len(temp[i])):
self.temps[i].append(temp[i][j].temperature)
def getMats(self):
self.mats = []
temp = self.dr.myGrid.fields
for i in range(len(temp)):
self.mats.append([])
for j in range(len(temp[i])):
self.mats[i].append(temp[i][j].density)
self.mats
def setUserInput(self):
str = raw_input("What do you want: Ground or Air? (The default is
air) \n")
if(str == "Ground" or str == "ground"):
self.type = 1
else:
self.type = 2
def getAirPts(self):
temp = self.dr.myGrid.fields
for i in range(len(temp)):
for j in range(len(temp[i])):
if(temp[i][j].material == 'air'):
self.airData.append(temp[i][j].temperature)
return
def getBridgePts(self):
temp = self.dr.myGrid.fields
for i in range(len(temp)):
for j in range(len(temp[i])):
if(temp[i][j].material == 'concrete'):
self.bridgeData.append(temp[i][j].temperature)
return
def getGroundPts(self):
if (type == 1):
return None
else:
temp = self.dr.myGrid.fields
for i in range(len(temp)):
for j in range(len(temp[i])):
if(temp[i][j].material == 'soil'):
self.groundData.append(temp[i][j].temperature)
return
def addTimeSteps(self):
self.time.append(self.step)
def update(self, *args):
print "WTF Delta?!?"
self.step = 0
if self.background is None:
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
self.updateData()
# restore the clean slate background
self.canvas.restore_region(self.background)
# update the data
print "GROUND DATA:"
print len(self.groundData)
print "TIME DATA"
print len(self.time)
if(self.type != 2):
self.groundLine = self.ax.plot(self.groundData , self.time,
'g-+')
self.bridgeLine = self.ax.plot(self.bridgeData , self.time,
'r-o')
self.airLine = self.ax.plot(self.airData, self.time, 'b-s')
self.contour = self.ax2.contourf(self.temps)
self.colorbar = self.fig.colorbar(self.contour)
# just draw the animated artist
self.ax.draw_artist(self.groundLine)
self.ax.draw_artist(self.airLine)
self.ax.draw_artist(self.bridgeLine)
self.ax.draw_artist(plt.contourf)
# self.ax.draw_artist(colorbar)
# just redraw the axes rectangle
self.canvas.blit(self.ax.bbox)
self.cnt += 1
self.step += .004
self.dr.run(10)
self.time.append(self.step*10)
return True
update.cnt = 0
update.background = None
def setup(self):
self.fig = plt.figure()
self.ax = self.fig.add_subplot(211)
self.ax2 = self.fig.add_subplot(212)
self.canvas = self.fig.canvas
self.ax.grid() # to ensure proper background restore
self.canvas.draw()
# create some globals
self.airData = []
self.groundData = []
self.bridgeData = []
self.time = []
self.step = 0
self.setUserInput()
self.temps = []
self.mats = []
self.dr = Driver(.5, .5, 0.0004, type, (7,7,9,9), (16,16))
self.cnt = 0
self.background = None
# don't use time steps over 4 * 10 ** -4
self.updateTemps()
self.gmats = self.getMats()
# create the initial graphs
self.contour = self.ax2.contourf(self.temps)
self.colorbar = self.fig.colorbar(self.contour)
self.groundLine, = self.ax.plot(self.groundData , self.time, 'g-+')
self.bridgeLine, = self.ax.plot(self.bridgeData , self.time, 'r-o')
self.airLine, = self.ax.plot(self.airData , self.time, 'b-s')
if __name__ == "__main__":
mygui = Gui()
def start_anim(event):
gobject.idle_add(mygui.update)
mygui.canvas.mpl_disconnect(start_anim.cid)
mygui.setup()
start_anim.cid = mygui.canvas.mpl_connect('draw_event', start_anim)
plt.show()
···
--
View this message in context: http://www.nabble.com/We-are-on-the-Home-strech-and-NEED-help-tp22795527p22795527.html
Sent from the matplotlib - users mailing list archive at Nabble.com.