|  | 
 
| 在评价模型当中,经常需要到多模型多指标同时显示,如何实现多个子图的legend放在一起呢?这是可以使用画布figure的suptitle,具体实现代码如下: 复制代码import numpy as np
import pickle
import matplotlib.pyplot as plt# plt 用于显示图片
file = ['scnn', 'scg', 'scga']
color = ['-r', '-g', '-b']
# plt.style.use('dark_background')
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
fig.suptitle('')
for k in range(len(file)):
    with open(file[k] + '.txt', 'rb') as file_pi:
           ggn_history = pickle.load(file_pi)
    y_loss = ggn_history['loss']
    y_err = ggn_history['accuracy']
    ax1.plot(y_err[0:20], color[k])
    ax2.plot(y_loss[0:20], color[k])
ax1.set_title('accuracy')
ax2.set_title('loss')
ax1.set_xlabel('epochs')
ax2.set_xlabel('epochs')
fig.legend(('scn', 'scg', 'scga'), ncol=3, loc='upper center')
plt.savefig('loss_acc.png')
plt.show()
 | 
 
x本帖子中包含更多资源您需要 登录 才可以下载或查看,没有帐号?立即注册  |