Python matplotlib图例上标的字体和颜色

有人可以帮助我使R2的写作看起来像其余的吗?尤其不是斜体。这是我的代码如下:

我在这里的时候,谁能告诉我怎么做

  • 以红色书写得到R2 = 0.97线以指示图上的红色线 或
  • 在该图例的图例中插入红线/红破折号吗?

我已经看到了其他在线处理方式,但是格式化图例的方式不允许这样做。

plt.rcParams["font.family"] = "Cambria"
fig,ax = plt.subplots()
ax.scatter(y_test,y_predicted,s=10,color='darkslateblue',linewidths=1)
ax.plot([y.min(),y.max()],[y.min(),'k-',lw=2,)
ax.set_xlabel('Actual (%)',fontsize='large')
ax.set_ylabel('Predicted (%)',fontsize='large')
y_test,y_predicted = y_test.reshape(-1,1),y_predicted.reshape(-1,1)
ax.plot(y_test,LinearRegression().fit(y_test,y_predicted).predict(y_test),color="red",lw=2)
ax.set_title('H2O REF')
handles = [mpl_patches.Rectangle((0,0),1,fc="white",ec="white",lw=0,alpha=0)] * 4
labels = []
labels.append("$R^2$ = {0:.2g}".format(Rsquared))
labels.append("RMSE = {0:.2g}".format(rmse))
labels.append("MAE = {0:.2g}".format(mae))
ax.legend(handles,labels,loc='best',fontsize='x-large',fancybox=True,framealpha=0.7,handlelength=0,handletextpad=0)
plt.show()

enter image description here

谢谢:)

相关文章

Python中的函数(二) 在上一篇文章中提到了Python中函数的定...
Python中的字符串 可能大多数人在学习C语言的时候,最先接触...
Python 面向对象编程(一) 虽然Python是解释性语言,但是它...
Python面向对象编程(二) 在前面一篇文章中谈到了类的基本定...
Python中的函数(一) 接触过C语言的朋友对函数这个词肯定非...
在windows下如何快速搭建web.py开发框架 用Python进行web开发...