如何在matplotlib中创建图例

2024-04-19 02:01:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在处理一个回归问题,我想绘制3个数据帧。我不知道如何设置数据帧的标签。我要蓝色->;实际,绿色->;SVR,红色->;MLR。你知道吗

代码有什么问题?你知道吗

ax1 = y_test[1800:1900].plot(color='blue', linewidth=3)
predicted_y[1800:1900].plot(color='green', linewidth=3, ax =ax1)
predicted_y1[1800:1900].plot(color='red', linewidth=3, ax=ax1)
plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),   prop={'size':35})
plt.show()

我画这个,它显示我所有的颜色与0值。你知道吗


Tags: 数据gtplot绘制plt标签axcolor
1条回答
网友
1楼 · 发布于 2024-04-19 02:01:50

我认为,如果你在绘图中添加标签,它应该会起作用:

ax1 = y_test[1800:1900].plot(color='blue', linewidth=3, label = 'ACTUAL')
predicted_y[1800:1900].plot(color='green', linewidth=3, ax =ax1, label = 'SVR')
predicted_y1[1800:1900].plot(color='red', linewidth=3, ax=ax1, label = 'MVR')
plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),   prop={'size':35})
plt.show()

相关问题 更多 >