我创建了这个函数
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启动新图表
在生成下一个绘图之前,可以运行
plt.cla()
和plt.clf()
清除轴和图形;我通常把这些放在绘图函数的顶部,在您的例子中是plotPrediction
见When to use cla(), clf() or close() for clearing a plot in matplotlib?
相关问题 更多 >
编程相关推荐