【发布时间】:2013-12-13 08:27:06
【问题描述】:
这是我的代码,
import numpy as np
import math
import matplotlib.pyplot as plt
#Voltages
V,I = np.genfromtxt('Photocurrent_graph_2.csv', dtype=float, delimiter=',',
usecols=(0,2), skiprows=1, unpack=True)
z = np.polyfit(V,I,6)
def function(x):
return (z[0])*x**6 (z[1])*x**5 + (z[2])*x**4 + (z[3])*x**3 + (z[4])*x**2 + (z[6])*x + z[7]
plt.plot(V, function(V))
plt.plot(V,I,'ro')
如果我注释掉 plt.plot(V, function(V)) 行,python 不会给我任何错误。我做错了什么?
编辑:
我遵循了 iCodez 的建议,但没有收到新的错误消息,
return (z[0])*x**6 + (z[1])*x**5 + (z[2])*x**4 + (z[3])*x**3 + (z[4])*x**2 + (z[6])*x + z[7]
IndexError: index 7 is out of bounds for axis 0 with size 7
【问题讨论】:
标签: python python-2.7 matplotlib callable