怎样在折线图中添加R^2作为图例?

我想在折线图中添加R^2做为图例,但是我现在只能添加折线图的拟合曲线的函数式,请问可以帮我一下么?

import matplotlib.pyplot as plt  
import numpy as np 
import pylab as pl 
import pylab
y = df["rain"]  
x = df["SITE"] 
fig, ax = plt.subplots() 
ax.plot(x, y) 
ax.set(xlabel='year', ylabel='P', title='rain') 
ax.grid() 
z = np.polyfit(x, y, 1)  
p = np.poly1d(z)  
pylab.plot(x,p(x), "y--") 
pl.plot(x, y, 'og-', label=("y=%.6fx+(%.6f)"%(z[0],z[1]))) 
pl.legend()

用annotate显示函数式,用label显示图例。示例如下:

import matplotlib.pyplot as plt
import numpy as np
import pylab as pl
import pylab
y = np.array([3.2,4.3,2.1,1.8,4.5,3.3])
x = np.array([1,2,3,4,5,6])
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set(xlabel='year', ylabel='P', title='rain')
ax.grid()
z = np.polyfit(x, y, 1)
p = np.poly1d(z)
pylab.plot(x, p(x), "y--")
pl.plot(x, y, 'og-', label="R^2")

pl.annotate(text=("y=%.6fx+(%.6f)" % (z[0], z[1])), xy=(2,4.3), xytext=(2.5, 3.8))
pl.show()