matplotlib在多个文件中打印错误

2024-06-25 05:26:46 发布

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

我创建了这个函数

def plotPrediction(testY, predictY, testYIndex, predictIndex, fileName):
    # Use datetime for creating date objects for plotting
    # Plot the actual values
    plt.plot(testY.index, testY[testYIndex], 'b-', label = 'actual');
    # Plot the predicted values
    plt.plot(testY.index, predictY[:, predictIndex] , 'ro', label = 'prediction')
    plt.xticks(rotation = '60'); 
    plt.legend()
    # Graph labels
    plt.xlabel('Date'); plt.ylabel(testYIndex); plt.title('Actual and Predicted DepositCount');
    plt.savefig(fileName+testYIndex+'.png')

然后我通过执行以下操作调用此函数:

plotPrediction(testY, predictY, 'DepositCount',0, 'forestpredict');
plotPrediction(testY, predictY, 'DepositAmount',1, 'forestpredict');
plotPrediction(testY, predictY, 'WithdrawCount',2, 'forestpredict');
plotPrediction(testY, predictY, 'WithdrawAmount',3, 'forestpredict');

我的想法是,由于我的predictY有多个输出,我想在不同的png文件中绘制每个输出。但是,输出文件显示相同的图像(第一个图像除外)。我猜我需要清理画布,或者可能有一些函数告诉matplotlib启动新图表


Tags: the函数forplotpltfilenamevaluesactual