代码拉取完成,页面将自动刷新
from flask import Flask, send_file, render_template
from DataAnalysis.matplotIMG import Drawer
app = Flask(__name__)
@app.route('/plot')
def plot_image():
# 定义时间点和对应的数据
time_points = ['00:00:00', '01:00:00', '02:00:00', '03:00:00', '04:00:00', '05:00:00',
'06:00:00', '07:00:00', '08:00:00', '09:00:00', '10:00:00', '11:00:00', '00:00:00', '01:00:00',
'02:00:00', '03:00:00', '04:00:00', '05:00:00',
'06:00:00', '07:00:00', '08:00:00', '09:00:00', '10:00:00', '11:00:00']
data = [5, 10, 8, 4, 25, 12, 6, 22, 17, 23, 9, 55, 5, 10, 8, 4, 25, 12, 6, 22, 17, 23, 9, 55]
#
# # 创建图形和轴
# fig, ax = plt.subplots(figsize=(10, 6))
#
# # 计算时间点的中点位置
# time_positions = np.arange(len(time_points)) + 0.5
#
# # 绘制折线图,数据点落在时间区间的中点位置
# ax.plot(time_positions, data, marker='o')
#
# # 设置图形标题和轴标签
# ax.set_title('Interval Line Plot from 00:00 to 12:00')
# ax.set_xlabel('Time Intervals')
# ax.set_ylabel('Data')
#
# # # 设置 x 轴刻度和标签
# # ax.set_xticks(np.arange(len(time_points)))
# # ax.set_xticklabels(time_points, rotation=45)
# num_ticks = round(len(time_points) // 8)
# # num_ticks = int(num_ticks)
# # 设置 x 轴刻度和标签,每隔 2 个时间点显示一个标签
# ax.set_xticks(time_positions[::num_ticks])
# ax.set_xticklabels(time_points[::num_ticks], rotation=0)
# max_value = ((max(data) + 10) // 10 + 1) * 10
# ax.set_ylim(0, max_value)
# # 设置每个点的数字显示
# for i in range(len(time_points)):
# ax.text(i + 0.5, data[i] + 0.5, str(data[i]), ha='center', va='bottom')
# 将图表保存到内存中
buf = Drawer.draw_line(time_points, data)
# 返回图表作为响应
return send_file(buf, mimetype='image/png')
@app.route('/')
def index():
return render_template('IMGDemo.html')
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=5000)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。