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

谢谢:)

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...