Python 如何删除散点图图例中的方括号?

Python 如何删除散点图图例中的方括号?,python,numpy,matplotlib,Python,Numpy,Matplotlib,有没有办法从散点图回归线图例中删除方括号?这是我的密码: import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression x = np.array([0.5, 2.5, 4.5]).reshape((-1, 1)) y = np.array([1.19, 1.67, 2.01]) model = LinearRegr

有没有办法从散点图回归线图例中删除方括号?这是我的密码:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

x = np.array([0.5, 2.5, 4.5]).reshape((-1, 1))
y = np.array([1.19, 1.67, 2.01])

model = LinearRegression().fit(x, y.reshape((-1, 1)))

r_sq = model.score(x, y)
intercept=model.intercept_
slope=model.coef_
print('coefficient of determination:', r_sq)
print('intercept:', intercept)
print('slope:', slope)

y_predict = intercept + slope * x
print('predicted response:', y_predict, sep='\n')

x_all = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]).reshape((-1, 1))
y_all = model.predict(x_all)
#y_all=round(y_all, 2)
print(x_all)
print(y_all)

x1 = x_all[0,:]
y1 = y_all[0,:]

plt.plot(x_all, y_all, 'o', color='black', markersize=10)
plt.xlabel('Factor 1', fontsize=16)
plt.ylabel('Factor 2', fontsize=16)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)

m, b = np.polyfit(x_all.flatten(), y_all.flatten(), 1)
plt.plot(x, m*x + b, linestyle='-', color='black', label='y = {}+{}x, R² = {}'.format(np.round(intercept,2), np.round(slope,2), np.round(r_sq, 2)))
plt.legend(loc=(0.05, 0.85), fontsize=20)
这给出了以下曲线图:


但是,我没有尝试删除它们,有什么建议吗?

只传递标量,而不是
标签中的整个数组:

plt.plot(x, m*x + b, linestyle='-', color='black', 
         label='y = {}+{}x, R² = {}'.format(np.round(intercept,2).item(), 
                                            np.round(slope,2).item(), 
                                            np.round(r_sq, 2))
        )
输出: