使用以下代码仍然可以看到先前保存的照片。 已经有新保存的文件,但是在烧瓶中没有更改。
@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)
我该怎么办?
我想看这张图:
但是我仍然看到这个: