划过的梦神 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 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。