【发布时间】:2016-04-11 17:33:49
【问题描述】:
我有一个这样的数据框:
data = DataFrame({'Sbet': [1,2,3,4,5], 'Length' : [2,4,6,8,10])
然后我有一个函数可以绘制并拟合这些数据
def lingregress(x,y):
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
r_sq = r_value ** 2
plt.scatter(x,y)
plt.plot(x,intercept + slope * x,c='r')
print 'The slope is %.2f with R squared of %.2f' % (slope, r_sq)
然后我会在数据帧上调用函数:
linregress(data['Sbet'],data['Length'])
我的问题是如何在函数中将 x 轴标签和 y 轴标签设为 Sbet 和 Length 以及将绘图标题设为 Sbet vs Length 我已经尝试了一些东西,但我当我使用 plt.xlabel(data['Sbet']) 和 plt.title 时,往往会恢复整个专栏。
【问题讨论】:
标签: python numpy pandas matplotlib