def combineData(xdata,ydata,xlabel):
#if ydata is a simple vector, encapsulate it into a 2D list
if type(ydata[1]) is not list:
ydata = [[val] for val in ydata]
#if xdata is time data, add HH:MM:SS if it is missing (just 00:00:00)
if type(xdata[1]) is str:
#check if first 4 characters of xdata is a valid year
if len(xdata[1]) == 10 and int(xdata[1][:4]) > 0 and int(xdata[1][:4]) < 3000:
xdata[1:] = [val+' 00:00:00' for val in xdata[1:]]
#figure out independent variable headers
# if there is a title row, use that title
if type(ydata[0][0]) is str:
data = [[xdata[0]] + ydata[0]]
for i in xrange(1,len(xdata)):
data.append([xdata[i]]+ydata[i])
# otherwise, use a default labeling
else:
header = [xlabel]
for i in xrange(len(ydata[0])):
header.append('data'+str(i+1))
data = [header]
for i in xrange(len(xdata)):
data.append([xdata[i]]+ydata[i])
return data
#helper function, returns title as a valid JS identifier, prefixed by '_'.
评论列表
文章目录