我有这个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
答案 0 :(得分:-2)
可能是MatplotLib库的版本吗?也许检查您在本地和服务器上安装的版本。