Exception in Tkinter callback
Traceback (most recent call last):
File "D:\python\lib\lib-tk\Tkinter.py", line 1470, in call
return self.func(*args)
File "D:\python\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 236, in resize
self.show()
File "D:\python\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 239, in draw
FigureCanvasAgg.draw(self)
File "D:\python\lib\site-packages\matplotlib\backends\backend_agg.py", line 421, in draw
self.figure.draw(self.renderer)
File "D:\python\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "D:\python\lib\site-packages\matplotlib\figure.py", line 898, in draw
func(*args)
File "D:\python\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "D:\python\lib\site-packages\matplotlib\axes.py", line 1997, in draw
a.draw(renderer)
File "D:\python\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "D:\python\lib\site-packages\matplotlib\text.py", line 526, in draw
bbox, info = self._get_layout(renderer)
File "D:\python\lib\site-packages\matplotlib\text.py", line 305, in get_layout
clean_line, ismath = self.is_math_text(line)
File "D:\python\lib\site-packages\matplotlib\text.py", line 989, in is_math_text
if cbook.is_math_text(s):
File "D:\python\lib\site-packages\matplotlib\cbook.py", line 1839, in is_math_text
"matplotlib display text must have all code points < 128 or use Unicode strings")
ValueError: matplotlib display text must have all code points < 128 or use Unicode strings
Exception in Tkinter callback
Traceback (most recent call last):
File "D:\python\lib\lib-tk\Tkinter.py", line 1470, in __call_
return self.func(*args)
File "D:\python\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 236, in resize
self.show()
File "D:\python\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 239, in draw
FigureCanvasAgg.draw(self)
File "D:\python\lib\site-packages\matplotlib\backends\backend_agg.py", line 421, in draw
self.figure.draw(self.renderer)
File "D:\python\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "D:\python\lib\site-packages\matplotlib\figure.py", line 898, in draw
func(*args)
File "D:\python\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "D:\python\lib\site-packages\matplotlib\axes.py", line 1997, in draw
a.draw(renderer)
File "D:\python\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "D:\python\lib\site-packages\matplotlib\text.py", line 526, in draw
bbox, info = self._get_layout(renderer)
File "D:\python\lib\site-packages\matplotlib\text.py", line 305, in _get_layout
clean_line, ismath = self.is_math_text(line)
File "D:\python\lib\site-packages\matplotlib\text.py", line 989, in is_math_text
if cbook.is_math_text(s):
File "D:\python\lib\site-packages\matplotlib\cbook.py", line 1839, in is_math_text
"matplotlib display text must have all code points < 128 or use Unicode strings")
ValueError: matplotlib display text must have all code points < 128 or use Unicode strings
Process finished with exit code 0
代码
import random
import pylab
class Stock(object):
def init(self, price, distribution):
self.price=price
self.history =[price]
self.distribution = distribution
self.lastChange = 0
def setPrice(self, price):
self.price = price
self.history.append(price)
def getPrice(self):
return self.price
def makeMove(self, mktBias,mo):
oldPrice = self.price
baseMove= self.distribution() +mktBias
self.price =self.price*(1.0+baseMove)
self.price +=mo*random.gauss(.25,.25)*self.lastChange
if self.price < 0.01:self.price = 0.0
self.history.append(self.price)
self.lastChange = self.price - oldPrice
def showHistory(self,figNum):
pylab.figure(figNum)
pylab.plot(self.history)
pylab.title('Closing Price, Test '+str(figNum))
pylab.xlabel('Day')
pylab.ylabel('Price')
def unitTestStock():
def runSim(stks,fig,mo):
mean =0.0
for s in stks:
for d in range(numDays):
s.makeMove(bias,mo)
s.showHistory(fig)
mean+=s.getPrice()
mean=mean/float(numStks)
pylab.axhline(mean)
numStks=20
numDays=200
stks1=[]
stks2=[]
bias=0.0
mo=0
for i in range(numStks):
volatility=random.uniform(0,0.2)
d1=lambda:random.uniform(-volatility,volatility)
d2=lambda:random.gauss(0.0,volatility/2.0)
stks1.append(Stock(100.0,d1))
stks2.append(Stock(100.0,d2))
runSim(stks1,1,mo)
runSim(stks2,2,mo)
unitTestStock()
pylab.show()