Страница колбы остается до состояния графика (pyplot) - PullRequest
0 голосов
/ 25 ноября 2018

Ранее сохраненное изображение все еще видимо с кодом ниже.Уже сохраненные файлы уже есть, но они не изменены в колбе.

@app.route('/test')
def charttest():
    strFile = './static/images/new_plot.png'
    strFile2 = './static/images/new_plot2.png'

    plt.rcParams.update({'font.size': 8})

    # remove 
    if os.path.isfile(strFile):
        print('already exists')
        os.remove(strFile)
    if os.path.isfile(strFile2):
        print('already exists')
        os.remove(strFile2)

    use = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
       12, 14, 15, 17, 14, 23, 63, 23, 75, 23,
       30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31]

    use1 = []
    for i in use:
        use1.append(i * 0.8)

    t = np.array(
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
     11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
     21, 22, 23, 24, 25, 26, 27, 28, 29, 30])

    y = np.array(use)
    plt.bar(t,y, color='r', width = 0.3, label='use')
    plt.xlabel('data')
    plt.ylabel('mount')
    plt.legend()

    plt.xticks(t, ('1','2','3','4','5','6','7','8','9','10',
               '11','12','13','14','15','16','17','18','19','20',
               '21','22','23','24','25','26','27','28','29','30','31'))

    plt.savefig(strFile)
    plt.clf()  # clear figure
    plt.cla()  # clear axes
    plt.close()

    y_ = np.array(use)
    y1_ = np.array(use1)
    plt.bar(t, y_, color='r', width=0.3, label='apple')
    plt.bar(t + 0.4, y1_, color='g', width=0.3, label='banana')
    plt.xlabel('11 month')
    plt.ylabel('use power')
    plt.legend()

    plt.xticks(t, ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
               '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
               '21', '22', '23', '24', '25', '26', '27', '28', '29','30','31'))

    plt.savefig(strFile2)
    plt.clf()  # clear figure
    plt.cla()  # clear axes
    plt.close()
    return render_template('test.html', url = strFile, url2= strFile2)

Что мне делать?

Я хочу увидеть этот график:

enter image description here

Но я все еще вижу это:

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...