matplotlab循环画图

训练画图必须要把画板清空,否则会累加,用plt.clf()

import matplotlib.pyplot as plt


for i in range(10):
    history_train_loss = list(range(i*10,(i+1)*10))
    t = i+1
    history_train_accuracy = list(range(t*10,(t+1)*10))
    t = t+1
    history_train_iou = list(range(t*10,(t+1)*10))
    t = t+1
    history_test_loss = list(range(t*10,(t+1)*10))
    t = t+1
    history_test_accuracy = list(range(t*10,(t+1)*10))
    t = t+1
    history_test_iou = list(range(t*10,(t+1)*10))


    plt.subplot(1,1,1)      #  一行两列第一列
    plt.plot(history_train_accuracy,label="Training Accuracy")
    plt.plot(history_test_accuracy,label="Validation Accuracy")
    plt.plot(history_train_loss,label="Training Loss")
    plt.plot(history_test_loss,label="Validation Loss")
    plt.plot(history_train_iou,label="Training Iou")
    plt.plot(history_test_iou,label="Validation Iou")

    plt.title("Accuracy Loss and Iou")
    plt.legend()

    # 保存和显示
    plt.savefig('./trrr/unet_epoch%d'%i)
    plt.clf()

你可能感兴趣的:(python,机器学习,深度学习,pytorch)