gpt4 book ai didi

python - 移动到服务器时Python脚本失败-(Matplotlib版本)

转载 作者:太空宇宙 更新时间:2023-11-04 06:44:05 24 4
gpt4 key购买 nike

我有这个python脚本:

#!/usr/bin/python
import matplotlib.pyplot as plt
import numpy as np
import time
#from scipy.interpolate import spline

def myround(x, base=24*3600):
return int(base * round(float(x)/base))

def processFile(filename):
file = open(filename)
lastrawline="Hello"
rawline = file.readline()
#the array we have is going to be horizonal when we need vertical. So we have to deal with that.
dayold=[]
weekold=[]
threedayold=[]
seconds=[]
now=[]
count=0
for rawline in file:
splitline=rawline.split()
dayold.insert(0,splitline[4])
threedayold.insert(0,splitline[5])
weekold.insert(0,splitline[3])
seconds.insert(0,splitline[2])
now.insert(0,splitline[0])
count=count+1
return (seconds,now,dayold,threedayold,weekold)

def graph(seconds,now, dayold, threedayold,weekold):
dis=4*24*60*60
x = np.array(seconds[-dis:])

#x = np.arange(len(seconds))
ynow = np.array(now)
yday = np.array(dayold)
y3day = np.array(threedayold)
yweek = np.array(weekold)
# y2 should go on top, so shift them up
plt.plot(x,ynow, 'white')
plt.plot(x,yday)
plt.plot(x,y3day,'purple')
plt.plot(x,yweek)
plt.fill_between(x,ynow,yday,color='lightblue')
plt.fill_between(x,yday,y3day,color='green')
plt.fill_between(x,y3day,yweek,color='purple')
plt.fill_between(x,yweek,[0] *len(seconds),color='red')
currenttime=int(seconds[0])
print currenttime
lastweek=myround(currenttime-7*24*3600)
print lastweek
plt.xlim(lastweek, currenttime)
ticks=np.arange(lastweek,currenttime,24*3600)
labels=[time.strftime("%a", time.gmtime(x)) for x in ticks]
plt.xticks(ticks,labels)
plt.grid()
# plt.show()
plt.savefig('stress.png')

#processFile("/home/pgrads/joseph/Dropbox/emailAnalysis/resultsOldest.txt")
a=processFile("results.txt")
graph(a[0],a[1],a[2],a[3],a[4])


那产生了这张图,很棒。



至少在我的本地计算机上。

当我将其上传到服务器时,会引发以下错误。

Traceback (most recent call last):
File "./plotNextActionData.py", line 63, in <module>
graph(a[0],a[1],a[2],a[3],a[4])
File "./plotNextActionData.py", line 45, in graph
plt.fill_between(x,ynow,yday,color='lightblue')
File "/home/joereddington/env/matplotlib-1.4.0-py2.6-linux-x86_64.egg/matplotlib/pyplot.py", line 2820, in fill_between
interpolate=interpolate, **kwargs)
File "/home/joereddington/env/matplotlib-1.4.0-py2.6-linux-x86_64.egg/matplotlib/axes/_axes.py", line 4316, in fill_between
x = ma.masked_invalid(self.convert_xunits(x))
File "/home/joereddington/env/numpy-1.8.2-py2.6-linux-x86_64.egg/numpy/ma/core.py", line 2239, in masked_invalid
condition = ~(np.isfinite(a))
TypeError: Not implemented for this type


注释掉fill_between调用会很好地生成一个图形


这不是我想要的。知道发生了什么事吗? MatplotLib显然在工作,只是这些调用很困难...

编辑-版本。

家用机:

josephs-mbp-3$more scrap.py 
import numpy as np
import time
import matplotlib.pyplot
#from scipy.interpolate import spline

print np.__version__
print matplotlib.__version__
josephs-mbp-3$python scrap.py
1.6.2
1.1.1
josephs-mbp-3$


服务器:

 blout$more scrap.py 
import numpy as np
import time
import matplotlib.pyplot
#from scipy.interpolate import spline

print np.__version__
print matplotlib.__version__
blout$python scrap.py
1.8.2
1.4.0

最佳答案

MatplotLib库的版本可以吗?也许检查您在本地和服务器上安装了哪个版本。

关于python - 移动到服务器时Python脚本失败-(Matplotlib版本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25731897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com