划过的梦神 2017-03-10 10:56 采纳率: 33.3%
浏览 5067
已结题

python2.7.5 画图问题,图形不显示

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()

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-03-10 23:05
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题