首页 > 解决方案 > python 中是否有 plt.show(0) 的替代方法, plt.show(0) 不再起作用它现在显示错误?

问题描述

我正在运行一个循环,并在每个循环中绘制结果,之前我使用 plt.show(0) 冻结图形,并且在所有循环结束时,所有子图都出现在一个图形上。但是, plt.show(0) 现在显示错误。

我已经尝试过 plt.ioff() 和 plt.pause(0.01) 但它在新图形上单独绘制子图。

trials = 6
c = 2
r = int(trials / c)
for i in range(1, trials + 1):
    print('Trial {} of {}'.format(i, trials))

    # train NN
    weights, bias, avg_cost_func, m_weights, memory, trained_model, training_data = train_nn(nn_structure, mm_structure, inputs, outputs,                                                                     window_size, horizon, iter_num, eta, momentum)


    # FIGURE 1: plot the ROC curve for training data
    fig1 = plt.figure(1, figsize=(10, 40))
    fig1.suptitle('ROC curve for inhospital mortality classifier training data')

    # subplot
    fig1.add_subplot(r, c, i).plot(avg_cost_func)
    plt.title((('Trail {} of {}'.format(i, trials)), str(np.round(np.average(avg_cost_func), 5))))
    plt.ylabel('Average J')
    plt.xlabel('Iteration number')
    plt.pause(0.01)
    plt.show(0)
    plt.subplots_adjust(wspace=0.5, hspace=1.5)
plt.show()

文件“filename.py”,第 451 行,在 plt.show(0)

文件“C:\Users\n0762538\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py”,第 253 行,显示

返回 _show(*args, **kw)

TypeError: call () 接受 1 个位置参数,但给出了 2 个

标签: pythonmatplotlib

解决方案


推荐阅读