我想在折线图中添加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()